"""Schemas (DTOs) de los catálogos de referencia del CRM."""

from pydantic import BaseModel, ConfigDict, Field


class CatalogItemBase(BaseModel):
    code: str = Field(..., max_length=64)
    label: str = Field(..., max_length=255)
    parent_catalog: str | None = Field(None, max_length=60)
    parent_code: str | None = Field(None, max_length=64)
    sort_order: int = 0
    is_active: bool = True


class CatalogItemCreate(CatalogItemBase):
    pass


class CatalogItemUpdate(BaseModel):
    """PATCH: todos los campos opcionales."""

    code: str | None = Field(None, max_length=64)
    label: str | None = Field(None, max_length=255)
    parent_code: str | None = Field(None, max_length=64)
    sort_order: int | None = None
    is_active: bool | None = None


class CatalogItemResponse(CatalogItemBase):
    model_config = ConfigDict(from_attributes=True)

    id: int
    catalog: str
    tenant_id: int | None
    is_system: bool
    extra: dict | None = None  # metadata (ej. dimensiones de un tipo de equipo)


class CatalogMeta(BaseModel):
    """Metadata de un catálogo para la pantalla de administración."""

    catalog: str
    label: str
    scope: str  # 'global' | 'tenant'
    is_system: bool
    count: int
