import uuid

from django.db import models


class Client(models.Model):
    class ClientType(models.TextChoices):
        PROFESSIONAL = "professional", "Profesional / Cliente individual"
        COMPANY = "company", "Empresa / Estudio jurídico"

    class Status(models.TextChoices):
        ACTIVE = "active", "Activo"
        INACTIVE = "inactive", "Inactivo"

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField("Nombre / Razón social", max_length=300)
    trade_name = models.CharField("Nombre comercial", max_length=300, blank=True, default="")
    identifier = models.CharField(
        "RUT o identificador",
        max_length=30,
        blank=True,
        default="",
        help_text="RUT, Cédula RUT, u otro identificador fiscal",
    )
    email = models.EmailField("Email de contacto")
    phone = models.CharField("Teléfono", max_length=50, blank=True, default="")
    client_type = models.CharField(
        "Tipo",
        max_length=20,
        choices=ClientType.choices,
        default=ClientType.PROFESSIONAL,
    )
    status = models.CharField(
        "Estado",
        max_length=20,
        choices=Status.choices,
        default=Status.ACTIVE,
    )
    notes = models.TextField("Observaciones", blank=True, default="")
    created_at = models.DateTimeField("Fecha de creación", auto_now_add=True)
    updated_at = models.DateTimeField("Fecha de actualización", auto_now=True)

    class Meta:
        verbose_name = "cliente"
        verbose_name_plural = "clientes"
        ordering = ["name"]

    def __str__(self):
        label = self.trade_name or self.name
        return f"{label} ({self.get_client_type_display()})"
