"""
DTOs (Data Transfer Objects) para fracciones arancelarias
"""

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class TariffFractionCreateDTO(BaseModel):
    """DTO para crear una fracción arancelaria"""

    code: str = Field(..., max_length=10, description="Código completo de la fracción")
    fraction: str = Field(..., max_length=15, description="Fracción formateada")
    description: Optional[str] = Field(None, max_length=1000, description="Descripción")
    nico: Optional[str] = Field(None, max_length=10, description="Código NICO")
    umt: Optional[str] = Field(None, max_length=10, description="Unidad de medida de tarifa")
    adv_impo: Optional[str] = Field(None, max_length=20, description="Ad valorem importación")
    adv_expo: Optional[str] = Field(None, max_length=20, description="Ad valorem exportación")

    model_config = ConfigDict(from_attributes=True)


class TariffFractionUpdateDTO(BaseModel):
    """DTO para actualizar una fracción arancelaria"""

    fraction: Optional[str] = Field(None, max_length=15, description="Fracción formateada")
    description: Optional[str] = Field(None, max_length=1000, description="Descripción")
    nico: Optional[str] = Field(None, max_length=10, description="Código NICO")
    umt: Optional[str] = Field(None, max_length=10, description="Unidad de medida de tarifa")
    adv_impo: Optional[str] = Field(None, max_length=20, description="Ad valorem importación")
    adv_expo: Optional[str] = Field(None, max_length=20, description="Ad valorem exportación")

    model_config = ConfigDict(from_attributes=True)


class TariffFractionResponseDTO(BaseModel):
    """DTO para respuesta de fracción arancelaria (catálogo global)"""

    id: int
    code: str
    fraction: str
    description: Optional[str] = None
    nico: Optional[str] = None
    umt: Optional[str] = None
    adv_impo: Optional[str] = None
    adv_expo: Optional[str] = None
    dof: Optional[str] = None
    aplica_ieps: Optional[str] = None
    um_code: Optional[str] = None

    model_config = ConfigDict(from_attributes=True)


class TariffFractionBasicDTO(BaseModel):
    """DTO para información básica de fracción arancelaria"""

    code: str
    fraction: str
    description: Optional[str] = None
    nico: Optional[str] = None
    umt: Optional[str] = None
    adv_impo: Optional[str] = None
    adv_expo: Optional[str] = None

    model_config = ConfigDict(from_attributes=True)


class TariffFractionListDTO(BaseModel):
    """DTO para lista de fracciones arancelarias"""

    items: list[TariffFractionBasicDTO]
    total: int
    page: int
    page_size: int
    pages: int

    model_config = ConfigDict(from_attributes=True)


class TariffFractionSearchDTO(BaseModel):
    """DTO para búsqueda de fracciones arancelarias"""

    code: Optional[str] = Field(None, description="Buscar por código")
    fraction: Optional[str] = Field(None, description="Buscar por fracción")
    description: Optional[str] = Field(None, description="Buscar en descripción")
    nico: Optional[str] = Field(None, description="Filtrar por NICO")
    umt: Optional[str] = Field(None, description="Filtrar por UMT")

    model_config = ConfigDict(from_attributes=True)
