from pydantic import BaseModel, field_validator, ConfigDict
from typing import Optional, List, Any
from datetime import date

class InvPartAphisLpcosDTO(BaseModel):
    id: Optional[int] = None
    aphis_general_id: Optional[int] = None
    issuer: Optional[str] = None
    issuer_loc_qua: Optional[str] = None
    issuer_loc: Optional[str] = None
    issuer_loc_desc: Optional[str] = None
    uom: Optional[str] = None
    txn_type: Optional[str] = None
    type: Optional[str] = None
    number: Optional[str] = None
    date_qual: Optional[str] = None
    date: Optional[date] = None
    qty: Optional[str] = None

    model_config = ConfigDict(from_attributes=True)

    @field_validator('date', mode='before')
    @classmethod
    def empty_str_to_none(cls, v: Any) -> Any:
        if v == "":
            return None
        return v
