from typing import Optional
from decimal import Decimal
from pydantic import BaseModel, Field, ConfigDict

# --- Base DTOs ---


class UnitOfMeasureACEBase(BaseModel):
    code: str = Field(..., max_length=4, description="ACE Code")
    description: Optional[str] = Field(None, max_length=49)


class UnitOfMeasureOMABase(BaseModel):
    code: str = Field(..., max_length=10, description="OMA Code")
    description: Optional[str] = Field(None, max_length=200)


class UnitOfMeasureAmericanBase(BaseModel):
    code: str = Field(..., max_length=3, description="American Code")
    description: Optional[str] = Field(None, max_length=40)


class UnitOfMeasureCustomsBase(BaseModel):
    code: str = Field(..., max_length=10, description="Customs Code")
    description: Optional[str] = Field(None, max_length=50)
    a76_unit_code: Optional[str] = Field(None, max_length=5, description="Unidad SCAII")


class UnitOfMeasureBase(BaseModel):
    code: str = Field(..., max_length=20, description="Unit Code")
    description: Optional[str] = Field(None, max_length=100)
    description_en: Optional[str] = Field(None, max_length=100)
    customs_code: Optional[int] = Field(None)
    american_code: Optional[str] = Field(None, max_length=20)
    ace_code: Optional[str] = Field(None, max_length=20)
    oma_code: Optional[str] = Field(None, max_length=20)


class UnitOfMeasureGeneralBase(UnitOfMeasureBase):
    pass

# --- Create DTOs ---


class UnitOfMeasureACECreate(UnitOfMeasureACEBase):
    pass


class UnitOfMeasureOMACreate(UnitOfMeasureOMABase):
    pass


class UnitOfMeasureAmericanCreate(UnitOfMeasureAmericanBase):
    pass


class UnitOfMeasureCustomsCreate(UnitOfMeasureCustomsBase):
    pass


class UnitOfMeasureCreate(UnitOfMeasureBase):
    pass


class UnitOfMeasureGeneralCreate(UnitOfMeasureGeneralBase):
    pass

# --- Update DTOs ---


class UnitOfMeasureACEUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=4)
    description: Optional[str] = Field(None, max_length=49)


class UnitOfMeasureOMAUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=10)
    description: Optional[str] = Field(None, max_length=200)


class UnitOfMeasureAmericanUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=3)
    description: Optional[str] = Field(None, max_length=40)


class UnitOfMeasureCustomsUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=10)
    description: Optional[str] = Field(None, max_length=50)
    a76_unit_code: Optional[str] = Field(None, max_length=5)


class UnitOfMeasureUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=20)
    description: Optional[str] = Field(None, max_length=100)
    description_en: Optional[str] = Field(None, max_length=100)
    customs_code: Optional[int] = Field(None)
    american_code: Optional[str] = Field(None, max_length=20)
    ace_code: Optional[str] = Field(None, max_length=20)
    oma_code: Optional[str] = Field(None, max_length=20)


class UnitOfMeasureGeneralUpdate(UnitOfMeasureUpdate):
    pass

# --- Response DTOs ---


class UnitOfMeasureACEResponse(UnitOfMeasureACEBase):
    id: int
    model_config = ConfigDict(from_attributes=True)


class UnitOfMeasureOMAResponse(UnitOfMeasureOMABase):
    id: int
    model_config = ConfigDict(from_attributes=True)


class UnitOfMeasureAmericanResponse(UnitOfMeasureAmericanBase):
    id: int
    model_config = ConfigDict(from_attributes=True)


class UnitOfMeasureCustomsResponse(UnitOfMeasureCustomsBase):
    id: int
    model_config = ConfigDict(from_attributes=True)


class UnitOfMeasureResponse(UnitOfMeasureBase):
    id: int
    model_config = ConfigDict(from_attributes=True)


class UnitOfMeasureGeneralResponse(UnitOfMeasureResponse):
    pass
