"""
DTOs para el catálogo de claves FDA
"""
from pydantic import BaseModel, Field
from typing import Optional


class FDACatalogCreate(BaseModel):
    """DTO para crear una entrada en el catálogo FDA"""
    fda_key: str = Field(..., max_length=20, description="Clave FDA")
    description: str = Field(..., max_length=500, description="Descripción")
    fda_code: Optional[str] = Field(None, max_length=50, description="Código FDA")
    requirements: Optional[str] = Field(None, max_length=500, description="Requerimientos")
    manufacturer_number: Optional[str] = Field(None, max_length=50, description="Número de fabricante")
    country_of_production: Optional[str] = Field(None, max_length=100, description="País de producción")
    storage_status: Optional[str] = Field(None, max_length=100, description="Estatus de almacenaje")
    warehouse_code: Optional[str] = Field(None, max_length=20, description="Código de almacén")
    call_atl: Optional[str] = Field(None, max_length=20, description="CallAtl")

    model_config = {
        "from_attributes": True
    }


class FDACatalogUpdate(BaseModel):
    """DTO para actualizar una entrada en el catálogo FDA"""
    fda_key: Optional[str] = Field(None, max_length=20, description="Clave FDA")
    description: Optional[str] = Field(None, max_length=500, description="Descripción")
    fda_code: Optional[str] = Field(None, max_length=50, description="Código FDA")
    requirements: Optional[str] = Field(None, max_length=500, description="Requerimientos")
    manufacturer_number: Optional[str] = Field(None, max_length=50, description="Número de fabricante")
    country_of_production: Optional[str] = Field(None, max_length=100, description="País de producción")
    storage_status: Optional[str] = Field(None, max_length=100, description="Estatus de almacenaje")
    warehouse_code: Optional[str] = Field(None, max_length=20, description="Código de almacén")
    call_atl: Optional[str] = Field(None, max_length=20, description="CallAtl")

    model_config = {
        "from_attributes": True
    }



class FDACatalogResponse(BaseModel):
    """DTO para respuesta del catálogo FDA"""
    id: int
    fda_key: str
    description: str
    fda_code: Optional[str]
    requirements: Optional[str]
    manufacturer_number: Optional[str]
    country_of_production: Optional[str]
    storage_status: Optional[str]
    warehouse_code: Optional[str]
    call_atl: Optional[str]

    model_config = {
        "from_attributes": True
    }


# DTOs para FDA01 - Especificaciones
class FDASpecificationsBase(BaseModel):
    prod_code: Optional[str] = None
    commodity_desc: Optional[str] = None
    brand_name: Optional[str] = None
    disclaimer: Optional[str] = None
    pgm_code: Optional[str] = None
    proc_code: Optional[str] = None
    intnd_use_code: Optional[str] = None
    intnd_use_desc: Optional[str] = None
    temp_qual: Optional[str] = None
    temp_type: Optional[str] = None
    temp_degrees: Optional[float] = None
    temp_negative: Optional[float] = None
    temp_location: Optional[str] = None
    quantity_1: Optional[float] = None
    qty_uom_1: Optional[str] = None
    quantity_2: Optional[float] = None
    qty_uom_2: Optional[str] = None
    quantity_3: Optional[float] = None
    qty_uom_3: Optional[str] = None
    ctry_prod: Optional[str] = None
    ctry_source: Optional[str] = None
    ctry_growth: Optional[str] = None
    ctry_refusal: Optional[str] = None
    ctry_shipping: Optional[str] = None
    manuf_key: Optional[str] = None
    shipper_key: Optional[str] = None
    ult_cons_key: Optional[str] = None
    fda_imp_key: Optional[str] = None
    pn_subm_key: Optional[str] = None
    consol_key: Optional[str] = None
    producer_key: Optional[str] = None
    owner_key: Optional[str] = None
    deli_party_key: Optional[str] = None
    grower_key: Optional[str] = None
    dev_ini_imp_key: Optional[str] = None
    lacf_cont_1: Optional[str] = None
    lacf_cont_2: Optional[str] = None
    lacf_cont_3: Optional[str] = None
    pn_transmitter_key: Optional[str] = None

class FDASpecificationsCreate(FDASpecificationsBase):
    pass

class FDASpecificationsUpdate(FDASpecificationsBase):
    pass

class FDASpecificationsResponse(FDASpecificationsBase):
    id: int
    fda_catalog_id: int
    model_config = {"from_attributes": True}


# DTOs para FDA04 - Elementos Constitutivos
class FDAConstituentElementsBase(BaseModel):
    line: int
    ele_name: str
    ele_qty: Optional[float] = None
    ele_qty_uom: Optional[str] = None
    ele_pctg: Optional[float] = None

class FDAConstituentElementsCreate(FDAConstituentElementsBase):
    pass

class FDAConstituentElementsUpdate(FDAConstituentElementsBase):
    line: Optional[int] = None
    ele_name: Optional[str] = None

class FDAConstituentElementsResponse(FDAConstituentElementsBase):
    id: int
    fda_catalog_id: int
    model_config = {"from_attributes": True}


# DTOs para FDA23 - Códigos de Afirmación
class FDAAffirmationCodesBase(BaseModel):
    line: int
    aoc_code: str
    aoc_qual: Optional[str] = None

class FDAAffirmationCodesCreate(FDAAffirmationCodesBase):
    pass

class FDAAffirmationCodesUpdate(FDAAffirmationCodesBase):
    line: Optional[int] = None
    aoc_code: Optional[str] = None

class FDAAffirmationCodesResponse(FDAAffirmationCodesBase):
    id: int
    fda_catalog_id: int
    model_config = {"from_attributes": True}


# DTOs para FDA25 - Lotes de Producción
class FDALotProductionBase(BaseModel):
    line: int
    lot_number: str
    production_start_date: Optional[str] = None
    production_end_date: Optional[str] = None

class FDALotProductionCreate(FDALotProductionBase):
    pass

class FDALotProductionUpdate(FDALotProductionBase):
    line: Optional[int] = None
    lot_number: Optional[str] = None

class FDALotProductionResponse(FDALotProductionBase):
    id: int
    fda_catalog_id: int
    model_config = {"from_attributes": True}
