from fastapi import APIRouter, HTTPException
from app.agents.hotel_agent import HotelAgent
from app.utils.logger import CustomLogger
from app.schemas.chat import ChatRequest, ChatResponse

router = APIRouter()
logger = CustomLogger.get_logger()


@router.post("/chat", tags=['Chat endpoint'])
async def chat(args: ChatRequest) -> ChatResponse:
    try:
        question = args.question
        history = args.history

        hotel_agent = HotelAgent(
            question=question,
            chat_history=history,    
        )
        print(history)
        chat_response = await hotel_agent.ainvoke()
        return chat_response
    except Exception as e:
        logger.error(f"Failed to upload file: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Failed to upload file: {str(e)}")