from datetime import datetime
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class SectorBaseDTO(BaseModel):
    key: str = Field(..., description="Clave del sector (ej: 'XIX', 'IIa')", max_length=8)
    description: str = Field(..., description="Descripción del sector", max_length=150)
    authorized: Optional[bool] = Field(False, description="True = autorizado para PROSEC")


class SectorCreateDTO(SectorBaseDTO):
    pass


class SectorUpdateDTO(BaseModel):
    key: Optional[str] = Field(None, max_length=8)
    description: Optional[str] = Field(None, max_length=150)
    authorized: Optional[bool] = None


class SectorResponseDTO(SectorBaseDTO):
    id: int
    company_id: int
    tenant_id: int
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None

    model_config = ConfigDict(from_attributes=True)
