import arrow

from service_app_test.bases import RequestToApi
from service_app_test.api_configs import WagAPI, LocalAPI, BothAPIS

from service_app_test.test_application.evyos.company_employee import (
    run_company_and_depends,
)
from service_app_test.test_application.evyos.address_building import (
    run_address_to_building,
)
from service_app_test.test_application.evyos.datas.get_type_codes import (
    get_type_codes_key_and_class,
)
from service_app_test.test_application.evyos.decision_book import (
    run_decision_book_depends,
    list_decision_books,
)
from service_app_test.test_application.evyos.decision_book_items import (
    run_decision_book_items,
    send_invitation_to_building_residents,
    collect_invitation_to_building_residents,
    assign_people_to_pre_or_wrt,
)


login_creds_employee = {
    "domain": "evyos.com.tr",
    "access_key": "karatay.berkay.sup@evyos.com.tr",
    "password": "string",
    "remember_me": False,
    "password_token": "z5nPguDu6PrY_94KlTGxGBCMcK6rZcDl5AGqO5aHWY7TcQF8LJGYikMQs9labvqdz5yM7vE_f8Zq_vqp00o3EnWwWCWhel-EsMcAujBKNRjV3jC_4xk0_1r_unIYogWAjz_spZipX6pncsch2ngvv0dpx4lHSiZ5QrDTA1RefQ",
}
access_key_president = "bmanco@example.net"
login_creds_occupant = {
    "domain": "evyos.com.tr",
    "access_key": access_key_president,
    "password": "string",
    "remember_me": False,
    "password_token": "o_2Y_yXS-cl6MxLbzLrXQetXTlDLD3UBDTQNa_mBMyzSOVIgx3LGbnufLRJjd4g6BWFbwVgJIUxbK-Pi0R5dwxfVJKyoEeDdej40uRHSsElKR16nvnqgFB_BJ4nmyN0KSunZHra5NqHJor17EGExOSmlttZV5dC7vFsrc-GUkg",
}
wrt_creds_occupant = {
    "domain": "evyos.com.tr",
    "access_key": access_key_president,
    "password": "string",
    "remember_me": False,
    "password_token": "",
}

add_with_employee = True
add_with_occupant = None
assign_people_to_create_item = 0

# selection_list = None
selection_list = [
    # "7e370616-7bcf-469f-b9a2-c0da55463939",
    # "c2d385d8-b772-4ecd-be89-8c468738654a",
]
# selection_list = None
manager_token = ""
writers_token = manager_token
people_uu_id_list = []
list_of_attendees = []


local_api = RequestToApi()
local_api.overwrite_base_url(base_url=LocalAPI.base_url)

if add_with_employee:
    print(
        "local_api",
        local_api.post(endpoint="authentication/login", data=login_creds_employee).text,
    )

    exit()
    local_api.selected_object = local_api.login_via_email_and_password(
        login_data=login_creds_employee, is_password_valid=False
    )
    print("local_api", local_api.headers)

    print("select_company_uu_id", local_api.selected_object)
    exit()
    run_company_and_depends(
        company_uu_id=local_api.selected_object, requester=local_api
    )
    run_address_to_building(requester=local_api)
    exit()

if add_with_occupant:
    local_api.selected_object = local_api.login_via_email_and_password(
        login_data=login_creds_occupant,
        is_password_valid=False,
        selection_list=selection_list,
    )
    if assign_people_to_create_item == 0:
        selected_decision_book_uu_id = run_decision_book_depends()
        send_invitation = {
            "build_decision_book_uu_id": selected_decision_book_uu_id,
            "message": "Request for a Regular Building Meeting",
            "planned_date": arrow.now().shift(days=2).date().__str__(),
        }
        send_invitation_to_building_residents(send_invitation_dict=send_invitation)
    if assign_people_to_create_item == 1:
        count = 17
        list_of_attendees.insert(0, manager_token)
        collect_invitation_to_building_residents(
            attended_dict_list=list_of_attendees, attend_count=count + 1
        )
    elif assign_people_to_create_item == 2:
        assign_people_to_pre_or_wrt(
            person_uu_id=people_uu_id_list[0],
            manager_token=manager_token,
            occupant_code="MT-VPR",
        )
        assign_people_to_pre_or_wrt(
            person_uu_id=people_uu_id_list[1],
            manager_token=manager_token,
            occupant_code="MT-WRT",
        )
        assign_people_to_pre_or_wrt(
            person_uu_id=people_uu_id_list[2],
            manager_token=manager_token,
            occupant_code="MT-PRS",
        )
    elif assign_people_to_create_item == 3:
        local_api.selected_object = local_api.login_via_email_and_password(
            login_data=wrt_creds_occupant,
            is_password_valid=True,
            selection_list=selection_list,
        )
        selected_decision_book_uu_id = list_decision_books()["data"][0]["uu_id"]
        print("select_company_uu_id", local_api.selected_object)
        is_fixed_price = False

        info_type_d_uu_id = get_type_codes_key_and_class(
            class_name="BuildDuesTypes", key_name="BDT-D"
        )["data"]["uu_id"]
        unit_price = 15.90
        run_decision_book_items(
            writers_token=writers_token,
            unit_price=unit_price,
            is_fixed=is_fixed_price,
            info_type_uu_id=info_type_d_uu_id,
        )
        is_fixed_price = True

        info_type_a_uu_id = get_type_codes_key_and_class(
            class_name="BuildDuesTypes", key_name="BDT-A"
        )["data"]["uu_id"]
        start_date, end_date = "2024-11-01", "2025-02-01"
        unit_price = 850
        run_decision_book_items(
            writers_token=writers_token,
            unit_price=unit_price,
            is_fixed=is_fixed_price,
            info_type_uu_id=info_type_a_uu_id,
            start_date=start_date,
            end_date=end_date,
        )

        info_type_a_uu_id = get_type_codes_key_and_class(
            class_name="BuildDuesTypes", key_name="BDT-R"
        )["data"]["uu_id"]
        unit_price = 5000
        run_decision_book_items(
            writers_token=writers_token,
            unit_price=unit_price,
            is_fixed=is_fixed_price,
            info_type_uu_id=info_type_a_uu_id,
            start_date=start_date,
            end_date=end_date,
        )

        info_type_a_uu_id = get_type_codes_key_and_class(
            class_name="BuildDuesTypes", key_name="BDT-R"
        )["data"]["uu_id"]
        unit_price = 2000
        run_decision_book_items(
            writers_token=writers_token,
            unit_price=unit_price,
            is_fixed=is_fixed_price,
            info_type_uu_id=info_type_a_uu_id,
            start_date=start_date,
            end_date=end_date,
        )

        info_type_a_uu_id = get_type_codes_key_and_class(
            class_name="BuildDuesTypes", key_name="BDT-L"
        )["data"]["uu_id"]
        unit_price = 750
        run_decision_book_items(
            writers_token=writers_token,
            unit_price=unit_price,
            is_fixed=is_fixed_price,
            info_type_uu_id=info_type_a_uu_id,
            start_date=start_date,
            end_date=end_date,
        )
