from enum import Enum
from pydantic import BaseModel, Field
from typing import Any, Dict, List, Literal, Optional

class ChatRequest(BaseModel):
    query: str
    session_id: Optional[str] = None
    history: List[Dict[str, Any]] = Field(default_factory=list)


class HotelChatRequest(BaseModel):
    query: str
    session_id: Optional[str] = None
    history: List[Dict[str, Any]] = Field(default_factory=list)
    reservation_details: Optional[Dict[str, Any]] = Field(
        default=None,
        description=(
            "Guest lookup fields used by get_reservation_details and get_available_addons: "
            "email, confirmation_number, hotel_id, and sub_hotel_id. "
            "Optional authorization/token may be included for LS catalog APIs."
        ),
    )

class HotelChatResponse(BaseModel):
    event: Literal["answer", "lookup_answer", "support_escalation"]
    data: Dict[str, Any] = Field(
        description="Contains `answer` (assistant reply) and `history` (updated conversation history)."
    )


class Message(BaseModel):
    role: str
    content: str

class ChatResponse(BaseModel):
    answer: str
    sources: Optional[List[int]] = []

class ClassifyResponse(BaseModel):
    answer: str = Field(
        description=(
            "A clear, accurate, and self-contained answer to the user's question, "
            "based only on the provided context. Do not include information not present in the context."
        )
    )
    
    video_start_timestamp: Optional[str] = Field(
        default=None,
        description=(
            "Start timestamp of the relevant segment in the video. always return the video start timestamp if answer is related to a video. if answer is not related to a video, return null.\n"
            "Rules:\n"
            "- Format: MM:SS or HH:MM:SS\n"
            "- provide me exact timestamp in the format MM:SS or HH:MM:SS where the answer is related to a video.\n"
            "- Do NOT include in the answer text.\n"
            "- Return null if not confidently available.\n"
        )
    )
    
    video_end_timestamp: Optional[str] = Field(
        default=None,
        description=(
            "End timestamp of the relevant segment in the video. always return the video end timestamp if answer is related to a video. if answer is not related to a video, return null.\n"
            "Rules:\n"
            "- Format: MM:SS or HH:MM:SS\n"
            "- Must be >= start timestamp.\n"
            "- If unclear, return null.\n"
        )
    )
    video_url: Optional[str] = Field(
        default=None,
        description=(
            "Video URL associated with the answer. always return the video URL if present in the context and video context is related to a user query and includes the user query solution else return null."
        )
    )
    

    language: Literal["en", "hi", "gu"] = Field(
        description=(
            "Language of the user query.\n"
            "Rules:\n"
            "- 'en' for English\n"
            "- 'hi' for Hindi\n"
            "- 'gu' for Gujarati\n"
            "- Must match the answer language exactly.\n"
        )
    )
            
    next_possible_questions: list[str] = Field(
        default=[],
        description=(
            "Generate up to 3 highly relevant follow-up questions based ONLY on the below topics and context. "
            "Rules:\n"
            "- Questions must stay within the SAME feature/module as the answer.\n"
            "- Do NOT switch to a different feature.\n"
            "- Prefer task-based or action-based questions.\n"
            "- Use the SAME language as the user.\n"
            "AND: TOPIC IS THIS: \n"
                "- Reservations / bookings\n"
                "- Create promotions\n"
                "- Create room\n"
                "- email templates\n"
                "- Customer management\n"
                "- Dashboard\n"
                "- Add product\n"
                "- Gift cards\n"
                "- Gift shop / POS\n"
                "- payment methods\n"
                "- rate calendar\n"
                "- revenue dashboard\n"
                "- tape chart\n"
                "- policies\n"
                "- reports\n"
                "- subscribers\n"
                "- negotiated customers management\n"
                "- restrictions\n"
                "- modify cancel reservation\n"
                "- hold and block reservation\n"
                "- housekeeping\n"
                "- generate invoice\n"
                "- email confirmation\n"
            "Don't add the residence related questions in the next possible questions unless the user asks about the residence."
        )
    )
    
class AgentRetrieverResponse(BaseModel):
    query: str = Field(
        description="Convert the user's request into a concise, keyword-based standalone search query in ENGLISH. "
            "If the user input is in other languages, translate it into English first."
            "Focus on key actions, entities, and system features. "
            "Use short phrases, not full sentences."
    )
    question: str = Field(
        description="Rewrite the latest user query in english language but rephrase it to make it a standalone question and help better similarity search."
    )


class HumanEscalationArgs(BaseModel):
    query: str = Field(
        description=(
            "Concise work request for the hotel staff describing only unresolved guest action(s). "
            "Exclude requests already acknowledged in Admin: system messages. "
            "Do not write a full conversation summary."
            "don't generate any query like i added or  confirmed becuase it's added by hotel admin or staff"
        )
    )


class GetReservationDetailsArgs(BaseModel):
    """No arguments. Reservation context comes from the current guest session."""
    pass


class GetAvailableAddonsArgs(BaseModel):
    """No arguments. Uses hotel_id from the current guest session."""
    pass


class HotelAgentResponse(BaseModel):
    answer: str = Field(
        description=(
            "A clear, friendly, direct reply to the guest based on retrieved hotel knowledge, "
            "hotel context, and conversation history. Do not invent hotel details. "
            "Do not mention documents, documentation, sources, knowledge base, or that you "
            "are seeing/checking/finding information. Speak as a hotel team member with the facts. "
            "Do not add soft offers to connect with staff or ask if they want confirmation "
            "after giving an informational answer."
        )
    )