from test_application.evyos.bases import requester, active_and_confirmed


employee_endpoint = "/employee/employ"
fire_endpoint = "/employee/fire"
staff_endpoint = "/staff/list"
people_endpoint = "/people/list"


def bind_people_to_employee(identity_no: str, staff_uu_id: str, expiry_starts: str):
    people_response = requester.post(
        data={"query": {"national_identity_id": identity_no}}, endpoint=people_endpoint
    )
    print("people_response tx", people_response.text)
    print("people_response", people_response.json())
    people_uu_id = people_response.json()["data"][0]["uu_id"]
    print("People UUID", people_uu_id)

    staff_response = requester.post(
        data={"query": {"uu_id": staff_uu_id}}, endpoint=staff_endpoint
    )
    print("staff_response tx", staff_response.text)
    print("staff_response", staff_response.json())
    staff_uu_id = staff_response.json()["data"][0]["uu_id"]
    print("Staff UUID", staff_uu_id)

    data_dict = {
        "people_uu_id": people_uu_id,
        "staff_uu_id": staff_uu_id,
        "expiry_starts": expiry_starts,
        **active_and_confirmed,
    }
    bind_employee_people_response = requester.post(
        data=data_dict, endpoint=employee_endpoint
    )
    print("bind_employee_people_response", bind_employee_people_response.text)
    print("bind_employee_people_response", bind_employee_people_response.json())


def fire_people_from_employee(identity_no: str, expiry_ends: str):
    people_response = requester.post(
        data={"query": {"national_identity_id": identity_no}}, endpoint=people_endpoint
    )
    print("people_response tx", people_response.text)
    print("people_response", people_response.json())
    people_uu_id = people_response.json()["data"][0]["uu_id"]
    print("People UUID", people_uu_id)

    data_dict = {
        "people_uu_id": people_uu_id,
        "expiry_ends": expiry_ends,
        **active_and_confirmed,
    }
    fire_employee_people_response = requester.post(
        data=data_dict, endpoint=fire_endpoint
    )
    print("fire_employee_people_response", fire_employee_people_response.text)
    print("fire_employee_people_response", fire_employee_people_response.json())


bind_people_to_employee(
    identity_no="46546125608",
    staff_uu_id="96f6a822-ae37-4644-a56a-811d47209c9d",
    expiry_starts="2024-10-01",
)
# fire_people_from_employee(
#     identity_no="91222781086"
# )
