from django.db import models


class Profession(models.Model):
    descripcion = models.CharField(max_length=50)

    def __str__(self):
        return self.descripcion
    class Meta:
        db_table='profession'


class DataSheet(models.Model):
    descripcion=models.CharField(max_length=50)
    historical_data = models.TextField()

    def __str__(self):
        return self.descripcion
    class Meta:
        db_table='datasheet'

class Customer(models.Model):
    name= models.CharField(max_length=50)
    address = models.CharField(max_length=50)
    profession=models.ManyToManyField(Profession)
    data_sheet= models.OneToOneField(DataSheet, on_delete=models.CASCADE)
    active = models.BooleanField(default=True)

    @property
    def status_message(self):
        if self.active:
            return "Customer active"
        else:
            return "Customer not active"

    def num_professions(self):
        return self.profession.all().count()

    def __str__(self):
        return self.name
    class Meta:
        db_table='customer'

class Document(models.Model):
    PP='PP'
    ID='ID'
    OT='OT'

    DOC_TYPES=(
    (PP,'Passport'),
    (ID,'Identity card'),
    (OT,'Others')
    )
    dtype=models.CharField(choices=DOC_TYPES, max_length=2)
    doc_number =models.CharField(max_length=50)
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)

    def __str__(self):
        return self.doc_number
    class Meta:
        db_table='document'
