from time import perf_counter
from json import loads

system_default = dict(
    is_confirmed=True,
    active=True,
    deleted=False,
    is_notification_send=True,
    created_by="System",
    confirmed_by="System",
)

json_directory = "/home/berkay/git-gitea-evyos/wag-managment-api-service-version-2"
json_directory += "/service_app_test/test_application/migrate_old_data/data"
print("json_directory", json_directory)


def read_json_file(json_file):
    with open(f"{json_directory}/{json_file}.json", "r", encoding="utf-8") as json_file:
        return loads(json_file.read())


def bulk_insert_alchemy_postgresql(
    active_session, table, data_list, on_conflict_constraints=None
):
    from sqlalchemy.dialects.postgresql import insert

    st = perf_counter()
    if on_conflict_constraints:
        session_execute = active_session.execute(
            insert(table)
            .values(data_list)
            .on_conflict_do_nothing(
                index_elements=on_conflict_constraints or [],
            )
        )
    else:
        session_execute = active_session.execute(insert(table).values(data_list))
    count_row = session_execute.rowcount
    print(
        f"Table : {table.__name__} count_row : {count_row} : time took : {round(perf_counter() - st, 2)} seconds"
    )
    active_session.commit()
    active_session.flush()
