"""Pydantic schemas for TableCombination and CombinedChairConfig endpoints."""

from sqlmodel import SQLModel


class CombinedChairConfigRead(SQLModel):
    id: str
    combination_id: str
    table_id: str
    slot_index: int
    side: str
    enabled: bool


class CombinedChairConfigUpdate(SQLModel):
    """Partial update — only ``enabled`` can be toggled."""

    enabled: bool


class TableCombinationCreate(SQLModel):
    name: str
    table_ids: list[str]


class TableCombinationUpdate(SQLModel):
    """Partial update — every field is optional so the endpoint serves both
    ``name`` / ``table_ids`` rewrites and the high-frequency
    ``merged_x`` / ``merged_y`` position drag saves."""

    name: str | None = None
    table_ids: list[str] | None = None
    merged_x: float | None = None
    merged_y: float | None = None


class TableCombinationRead(SQLModel):
    """Response model — includes nested CombinedChairConfig."""

    id: str
    restaurant_id: str
    name: str
    table_ids: list[str]
    combined_capacity: int
    # `None` = no user-edited position; frontend falls back to the centroid
    # of component tables. See `routers/table_combinations.py` and the
    # `mergedTableData` derivation in `/tables/+page.svelte`.
    merged_x: float | None = None
    merged_y: float | None = None
    chair_configs: list[CombinedChairConfigRead] = []
