"""Pydantic schemas for Table CRUD endpoints."""

from datetime import datetime

from sqlmodel import Field, SQLModel

from app.schemas.chair import ChairRead


class FloorTableCreate(SQLModel):
    zone_id: str | None = None  # auto-created "Main" zone if omitted
    label: str
    x: float = 0.0
    y: float = 0.0
    width: float = 80.0
    height: float = 80.0
    shape: str = "round"
    rotation: float = 0.0
    slot_count: int = Field(ge=1, default=4)


class FloorTableUpdate(SQLModel):
    zone_id: str | None = None
    label: str
    x: float = 0.0
    y: float = 0.0
    width: float = 80.0
    height: float = 80.0
    shape: str = "round"
    rotation: float = 0.0
    slot_count: int = Field(ge=1, default=4)


class FloorTableRead(SQLModel):
    """Table response including nested chairs."""

    id: str
    restaurant_id: str
    zone_id: str
    label: str
    x: float
    y: float
    width: float
    height: float
    shape: str
    rotation: float
    slot_count: int
    chairs: list[ChairRead] = []


class TableStatusReservation(SQLModel):
    """Reservation summary included in table status response."""

    id: str
    guest_name: str
    party_size: int
    reserved_at: datetime
    end_time: datetime
    status: str


class TableStatus(SQLModel):
    """Status of a single table at a point in time."""

    table_id: str
    table_label: str
    status: str  # "available" | "reserved" | "occupied" | "in_service"
    reservation: TableStatusReservation | None = None


class TableAvailabilityItem(SQLModel):
    """Availability of a single table for walk-in assignment."""

    table_id: str
    table_label: str
    capacity: int
    available: bool


class CombinationAvailabilityItem(SQLModel):
    """Availability of a table combination for walk-in assignment."""

    id: str
    name: str
    table_ids: list[str]
    combined_capacity: int
    available: bool


class AvailabilityResponse(SQLModel):
    """Response for walk-in availability check."""

    tables: list[TableAvailabilityItem]
    combinations: list[CombinationAvailabilityItem]
