from app.agents import AgentSchema

from app.agents.tools.send_email import send_email
from app.schemas.chat import ChatRequest
from app.agents.tools.add_to_cart_tool import add_to_cart
from app.agents.tools.search_room_tool import search_room

async def tool_map(result: AgentSchema, args: ChatRequest, checkin: str, checkout: str):
    if not result:
        return

    if result.tool.value == 'search_room_tool':
        yield "#qwerasdf"
        res = search_room(adultCount=result.params.adultCount,
                          childCount=result.params.childCount,
                          check_in=result.params.check_in,
                          check_out=result.params.check_out,
                          sortValue=result.sort.value,
                          keyValue=result.key.value,
                          room_count=result.room_count,
                          hotel_ids=result.hotel_ids)
        async for token in res:
            yield token        
    
    if result.tool.value == 'add_to_cart':
        if args.roomList:
            async for token in add_to_cart(args.roomList, checkin, checkout, result.params.room_type_id):
                yield token
    
    if result.tool.value == "add_billing_details":
        yield '#tEjdaY'
        
    # if result.tool.value == "cancel_reservation_tool":
    #     yield '#hlpwjw'
        
    if result.tool.value == "modify_reservation_tool":
        yield '#mrt311'

    if result.tool.value == "send_email_tool":
        if result.params.confirmation_number or result.params.confirmation_number != "":
            res = await send_email(result.params.confirmation_number)
            if res:
                yield "\n\nI have sent the email to the front desk. They will get back to you shortly. Is there anything else I can assist you with?"
            else:
                yield "\n\nI'm sorry, something went wrong while sending your request to the front desk. Please try again in a moment, or contact the front desk directly for assistance. Is there anything else I can help you with?"
        
    if result.tool.value == "clear_cart_tool":
        yield '#clearCart'

    if result.tool.value == 'no_tool':
        if result.room_type_ids:
            yield "#qwerasdf"
            res = search_room(adultCount=result.params.adultCount,
                    childCount=result.params.childCount,
                    check_in=result.params.check_in,
                    check_out=result.params.check_out,
                    sortValue=result.sort.value,
                    keyValue=result.key.value,
                    room_count=result.room_count,
                    hotel_ids=result.hotel_ids,
                    room_type_ids=result.room_type_ids)
            async for token in res:
                yield token