from django.db import models

# Create your models here.

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

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

  # RETURNS data to rest page
  def __str__(self):
    return self.description

class Customer(models.Model): 
  name = models.CharField(max_length=50)
  address = models.CharField(max_length=50)
  professions = models.ManyToManyField(Profession)
  # IF YOU delete the customer, it will delete their datasheet
  
  data_sheet = models.OneToOneField(DataSheet, on_delete=models.CASCADE, null=True, blank=True)
  # every person can have multiple docs
  # document = models.ManyToManyField(Document)

  def __str__(self): 
    return self.name


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