"""Pydantic schemas for dish chooser payloads."""

from __future__ import annotations

from pydantic import BaseModel, Field, model_validator


class DishItem(BaseModel):
    """A single menu-mode dish selection."""

    menu_item_id: str
    quantity: int = Field(ge=1)


class AgentDishItem(BaseModel):
    """A single dish selection from the agent path (name-based, not ID-based)."""

    menu_item_name: str
    quantity: int = Field(ge=1)


class DishSubmissionRequest(BaseModel):
    """Request body for dish submission (admin endpoint and saga payload).

    Exactly one of `dishes` (menu mode) or `dishes_text` (free-text mode)
    must be provided.
    """

    dishes: list[DishItem] | None = None
    dishes_text: str | None = None

    @model_validator(mode="after")
    def _check_mutual_exclusivity(self) -> DishSubmissionRequest:
        has_dishes = self.dishes is not None and len(self.dishes) > 0
        has_text = self.dishes_text is not None and self.dishes_text.strip() != ""
        if has_dishes and has_text:
            raise ValueError("Provide either 'dishes' or 'dishes_text', not both")
        if not has_dishes and not has_text:
            raise ValueError("Either 'dishes' or 'dishes_text' must be provided")
        return self
