from app.agents import AgentSchema, BillingFormStep

from app.agents.tools.special_request import special_request
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, hotel_id: str, sub_hotel_id: str):
    if not result:
        return

    yield f"#pets_{result.total_pets}"

    if result.tool.value == "note_special_request":
        if result.params.special_request and result.params.special_request != "":
            if result.params.confirmation_number and result.params.confirmation_number != "" and result.params.email and result.params.email != "":
                res = await special_request(result.params.email, result.params.confirmation_number, result.params.special_request, hotel_id, sub_hotel_id)
                yield res
            else:
                yield f"#special_request_new_{result.params.special_request}"

    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,
                          filters=result.filters,
                          room_count=result.room_count,
                          hotel_ids=result.hotel_ids,
                          hotel_id=hotel_id,
                          sub_hotel_id=sub_hotel_id)
        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, hotel_id, sub_hotel_id, result.room_count, result.hotel_ids):
                yield token
    
    if result.tool.value == "add_billing_details":
        # yield '#tEjdaY'
        if result.billing_form_step == BillingFormStep.addons:
            yield '#addons'
        elif result.billing_form_step == BillingFormStep.insurance:
            yield '#insurance'
        elif result.billing_form_step == BillingFormStep.customer_details_form:
            yield '#customer_details_form'
        elif result.billing_form_step == BillingFormStep.promo_code_form:
            yield '#promo_code_form'
        elif result.billing_form_step == BillingFormStep.payment_details_form:
            yield '#payment_details_form'
        
    # 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 and result.params.email and result.params.email != "" and 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,
                    filters=result.filters,
                    room_count=result.room_count,
                    hotel_ids=result.hotel_ids,
                    hotel_id=hotel_id,
                    sub_hotel_id=sub_hotel_id,
                    room_type_ids=result.room_type_ids)
            async for token in res:
                yield token
        
        if result.params.special_request and result.params.special_request != "":
            if result.params.confirmation_number and result.params.email and result.params.email != "" and result.params.confirmation_number != "" and result.params.email != "":
                res = await special_request(result.params.email, result.params.confirmation_number, result.params.special_request, hotel_id, sub_hotel_id)
                yield res
            else:
                yield f"#special_request_new_{result.params.special_request}"