import json
from app.agents.tools.search_room_tool import search_room


async def add_to_cart(roomList, checkin, checkout, id, hotel_id, sub_hotel_id, room_count, hotel_ids):
    
    if not id:
        res = search_room(adultCount=2,childCount=0,check_in=checkin,check_out=checkout,filters=None, room_count=room_count, hotel_ids=hotel_ids, hotel_id=hotel_id,sub_hotel_id=sub_hotel_id)
        async for token in res:
            yield token
        return

    for room_type_id in id:
        room = await find_room_by_type_id(rooms_list=roomList, target_type_id=room_type_id)
        if room:
            yield json.dumps({"fdGN32r": room})
    # yield "Room added to cart"
    return

async def find_room_by_type_id(rooms_list, target_type_id):
    for room in rooms_list:
        if room['id'] == target_type_id:
            return room
    return None