from django.db import models

class Sala(models.Model):
    numero = models.CharField(max_length=50)
    observacoes = models.TextField(null=True, blank=True)
    
    class Meta:
        ordering = ['numero']
    
    def __str__(self):
        return self.numero

class Usuario(models.Model):
    nome = models.CharField(max_length=50)
    serviço_prestado = models.CharField(max_length=50)
    cpf = models.CharField(max_length=11, null=True, blank=True)
    cnpj = models.CharField(max_length=14, null=True, blank=True)
    email = models.EmailField(max_length=50)
    telefone = models.CharField(max_length=50)
    sala = models.ForeignKey(Sala, on_delete=models.CASCADE)

    class Meta:
        ordering = ['nome']

    def __str__(self):
        return self.nome
    
class Visitante(models.Model):
    nome_visitante = models.CharField(max_length=50)
    email_visitante = models.EmailField(max_length=50)
    identidade_visitante = models.CharField(max_length=50, null=True, blank=True)
    CPF_visitante = models.CharField(max_length=11, null=True, blank=True)

    class Meta:
        ordering = ['nome_visitante']
    
    def __str__(self):
        return self.nome_visitante

class Visita(models.Model):
    visitante = models.ForeignKey(Visitante, on_delete=models.CASCADE)
    destino = models.ForeignKey(Sala, on_delete=models.CASCADE)
    motivo = models.CharField(max_length=50)
    data = models.DateTimeField(auto_now_add=True)
    atualizado = models.DateTimeField(auto_now=True)
    observacoes = models.TextField(null=True, blank=True)

    class Meta:
        ordering = ('-data',)

    def __str__(self):
        return self.visitante + + self.destino


from django.db import models

class Sala(models.Model):
    numero = models.CharField(max_length=50)
    observacoes = models.TextField(null=True, blank=True)
    
    class Meta:
        ordering = ['numero']
    
    def __str__(self):
        return self.numero

class Usuario(models.Model):
    nome = models.CharField(max_length=50)
    serviço_prestado = models.CharField(max_length=50)
    cpf = models.CharField(max_length=11, null=True, blank=True)
    cnpj = models.CharField(max_length=14, null=True, blank=True)
    email = models.EmailField(max_length=50)
    telefone = models.CharField(max_length=50)
    sala = models.ForeignKey(Sala, on_delete=models.CASCADE)

    class Meta:
        ordering = ['nome']

    def __str__(self):
        return self.nome
    
class Visitante(models.Model):
    nome_visitante = models.CharField(max_length=50)
    email_visitante = models.EmailField(max_length=50)
    identidade_visitante = models.CharField(max_length=50, null=True, blank=True)
    CPF_visitante = models.CharField(max_length=11, null=True, blank=True)

    class Meta:
        ordering = ['nome_visitante']
    
    def __str__(self):
        return self.nome_visitante

class Visita(models.Model):
    visitante = models.ForeignKey(Visitante, on_delete=models.CASCADE)
    destino = models.ForeignKey(Sala, on_delete=models.CASCADE)
    motivo = models.CharField(max_length=50)
    data = models.DateTimeField(auto_now_add=True)
    atualizado = models.DateTimeField(auto_now=True)
    observacoes = models.TextField(null=True, blank=True)

    class Meta:
        ordering = ('-data',)

    def __str__(self):
        return self.visitante + + self.destino

