"""Reference data schemas: zones, areas, locations, equipment types."""
from pydantic import BaseModel, ConfigDict, Field

from app.models.enums import LocationType


class ZoneOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str
    code: str


class AreaOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str
    code: str
    zone_id: int


class AreaWithZoneOut(AreaOut):
    zone: ZoneOut


class LocationOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str
    code: str
    type: LocationType
    is_default: bool


class EquipmentTypeOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str
    code: str
    unit: str
    is_serialized: bool
    default_return_days: int | None
    reorder_level: int


# --- Create/update payloads (admin-managed) ---


class ZoneCreate(BaseModel):
    name: str = Field(min_length=2, max_length=100)
    code: str = Field(min_length=1, max_length=20)
    description: str | None = None


class AreaCreate(BaseModel):
    zone_id: int
    name: str = Field(min_length=2, max_length=120)
    code: str = Field(min_length=1, max_length=20)


class LocationCreate(BaseModel):
    name: str = Field(min_length=2, max_length=120)
    code: str = Field(min_length=1, max_length=20)
    type: LocationType = LocationType.WAREHOUSE
    address: str | None = None
    is_default: bool = False


class EquipmentTypeCreate(BaseModel):
    name: str = Field(min_length=2, max_length=120)
    code: str = Field(min_length=1, max_length=20)
    unit: str = Field("pcs", max_length=20)
    is_serialized: bool = True
    default_return_days: int | None = Field(None, ge=0)
    reorder_level: int = Field(0, ge=0)
