from typing import Optional

from pydantic import BaseModel, ConfigDict, Field

from .models import LocationSystem


class LocationBase(BaseModel):
    clave_localizacion: str = Field(
        ..., max_length=20, description="Clave/código de la localización"
    )
    localizacion: Optional[str] = Field(
        None, max_length=200, description="Nombre o descripción"
    )
    system: LocationSystem = Field(
        ..., description="Contexto: fixed_asset (FA) o inventory"
    )


class LocationCreate(LocationBase):
    """Optional extra fields for fixed_asset; used only when system == FIXED_ASSET."""
    department: Optional[str] = Field(None, max_length=100)
    responsible: Optional[str] = Field(None, max_length=200)
    observations: Optional[str] = Field(None, description="Free text")


class LocationUpdate(BaseModel):
    clave_localizacion: Optional[str] = Field(None, max_length=20)
    localizacion: Optional[str] = Field(None, max_length=200)
    system: Optional[LocationSystem] = None


class LocationResponse(LocationBase):
    id: int

    model_config = ConfigDict(from_attributes=True)
