from typing import Optional

from pydantic import BaseModel, Field, ConfigDict, model_validator


class CreateRestaurantOfferRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    offer_id: str = Field(..., min_length=1, description="Restaurant identifier used for offer image storage path")
    occasion: str = Field(..., min_length=1, description="Occasion or theme for the offer, e.g. 'Valentine's Day', '8 March', 'Daily Special'")
    offer_items: str = Field(..., min_length=1, description="Curated list of offer items (dishes + drinks), 3–8 items with optional prices")
    logo_image_url: str = Field(..., min_length=1, description="Public URL to the restaurant logo image")
    visual_prompt: Optional[str] = Field(
        default=None,
        description=(
            "User description of the ambient scene and atmosphere — drives the background directly. "
            "Can describe people, setting, mood, lighting, activities. "
            "Examples: 'couples dancing in a dimly lit ballroom', "
            "'families gathered around a fireplace', "
            "'friends laughing on a sunny terrace with sea view', "
            "'elegant ladies having afternoon tea with flowers everywhere'"
        )
    )
    target_language: Optional[str] = Field(
        default=None,
        description=(
            "Optional language code or name to translate all offer content into before generating the image. "
            "Accepts ISO 639-1 codes (e.g. 'bg', 'de', 'fr', 'it') or full names (e.g. 'Bulgarian', 'German'). "
            "Prices and numbers are preserved as-is. Occasion title and item names are translated."
        )
    )
    city: Optional[str] = Field(
        default=None,
        description="Optional city identifier for analytics"
    )
    zavedenia_id: Optional[int] = Field(
        default=None,
        description="Optional Zavedenia restaurant identifier for analytics"
    )
    model: Optional[str] = Field(
        default=None,
        description="Optional OpenAI model override for image generation"
    )
    mock_data: bool = Field(
        default=False,
        description="If true, skip OpenAI and return mock image from menues/restaurant123/offer_9a8e94e6e2524de2abd34e584b315f79.png"
    )

    @model_validator(mode="before")
    @classmethod
    def apply_aliases(cls, data):
        if isinstance(data, dict):
            mapped = data.copy()
            if "offer_id" not in mapped and "zId" in mapped:
                mapped["offer_id"] = mapped["zId"]
            if "offer_id" not in mapped and "z_id" in mapped:
                mapped["offer_id"] = mapped["z_id"]
            if "offer_items" not in mapped and "offerItems" in mapped:
                mapped["offer_items"] = mapped["offerItems"]
            if "logo_image_url" not in mapped and "logoImageUrl" in mapped:
                mapped["logo_image_url"] = mapped["logoImageUrl"]
            if "visual_prompt" not in mapped and "visualPrompt" in mapped:
                mapped["visual_prompt"] = mapped["visualPrompt"]
            if "target_language" not in mapped and "targetLanguage" in mapped:
                mapped["target_language"] = mapped["targetLanguage"]
            if "city" not in mapped and "City" in mapped:
                mapped["city"] = mapped["City"]
            if "zavedenia_id" not in mapped and "zavedeniaId" in mapped:
                mapped["zavedenia_id"] = mapped["zavedeniaId"]
            if "mock_data" not in mapped and "mockData" in mapped:
                mapped["mock_data"] = mapped["mockData"]
            return mapped
        return data
