from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field


class AddressBase(BaseModel):
    account_id: int | None = None
    supplier_id: int | None = None
    address_type: str = Field("fiscal", max_length=20)
    street: str | None = Field(None, max_length=255)
    ext_number: str | None = Field(None, max_length=30)
    int_number: str | None = Field(None, max_length=30)
    neighborhood: str | None = Field(None, max_length=120)
    postal_code: str | None = Field(None, max_length=10)
    city: str | None = Field(None, max_length=120)
    state: str | None = Field(None, max_length=120)
    country: str | None = Field("MEX", max_length=3)  # ISO 3166-1 alfa-3 (alineado a catálogo pais)
    reference_notes: str | None = None
    is_primary: bool = False


class AddressCreate(AddressBase):
    pass


class AddressUpdate(BaseModel):
    address_type: str | None = Field(None, max_length=20)
    street: str | None = Field(None, max_length=255)
    ext_number: str | None = Field(None, max_length=30)
    int_number: str | None = Field(None, max_length=30)
    neighborhood: str | None = Field(None, max_length=120)
    postal_code: str | None = Field(None, max_length=10)
    city: str | None = Field(None, max_length=120)
    state: str | None = Field(None, max_length=120)
    country: str | None = Field(None, max_length=3)
    reference_notes: str | None = None
    is_primary: bool | None = None


class AddressResponse(AddressBase):
    model_config = ConfigDict(from_attributes=True)

    id: int
    tenant_id: int
    company_id: int
    created_at: datetime
    updated_at: datetime
