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 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 answer is related to a video. if answer is not related to a video, 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."
    )