"""API schemas (Pydantic) for Child. Schemas validate request bodies and shape responses. Separate from domain entities so the wire format can evolve independently. """ from datetime import date, datetime from uuid import UUID from pydantic import BaseModel, Field, field_validator from app.entities.child import Child class ChildCreate(BaseModel): workspace_id: UUID name: str = Field(min_length=1, max_length=255) birth_date: date preschool_start_date: date | None = None preschool_planning_days_per_year: int = Field(default=6, ge=0, le=30) @field_validator("preschool_start_date") @classmethod def validate_preschool_date(cls, v: date | None, info) -> date | None: """Preschool start date must be after birth date if both provided.""" if v is None: return v birth_date = info.data.get("birth_date") if birth_date and v <= birth_date: raise ValueError("preschool_start_date must be after birth_date") return v class ChildUpdate(BaseModel): """Partial update — all fields optional.""" name: str | None = Field(None, min_length=1, max_length=255) birth_date: date | None = None preschool_start_date: date | None = None preschool_planning_days_per_year: int | None = Field(None, ge=0, le=30) @field_validator("preschool_start_date") @classmethod def validate_preschool_date(cls, v: date | None, info) -> date | None: """Preschool start date must be after birth date if both provided.""" if v is None: return v birth_date = info.data.get("birth_date") if birth_date and v <= birth_date: raise ValueError("preschool_start_date must be after birth_date") return v class ChildResponse(BaseModel): id: UUID workspace_id: UUID name: str birth_date: date preschool_start_date: date | None preschool_planning_days_per_year: int created_at: datetime | None @classmethod def from_entity(cls, entity: Child) -> "ChildResponse": return cls( id=entity.id, workspace_id=entity.workspace_id, name=entity.name, birth_date=entity.birth_date, preschool_start_date=entity.preschool_start_date, preschool_planning_days_per_year=entity.preschool_planning_days_per_year, created_at=entity.created_at, )