from service_app_test.api_configs import BothAPIS
from service_app_test.bases import FilterObject


def migrate_people(requester: BothAPIS):
    # Migrate old data
    filter_object = FilterObject(
        page=1,
        size=100,
    )
    response = requester.wag_api.post(
        endpoint="/people/list",
        data=filter_object.dump(),
    )
    response_json = response.json()
    response_datas = response_json["data"]
    counter = 0
    for response_data in response_datas:
        new_response_data = dict()
        for key, value in dict(response_data).items():
            if value is not None and not str(value) == "None":
                new_response_data[key] = response_data[key]
        new_response_data.pop("uu_id", None)
        print("new_response_data", new_response_data)
        new_response_data["national_identity_id"] = f"000000000{str(counter).zfill(2)}"
        response = requester.local_api.post(
            endpoint="/people/create",
            data=new_response_data,
        )
        print("response", response.text)
        if response.ok:
            counter += 1
    return
