from Schemas import (
    Users,
    Services,
    Service2Events,
    Applications,
    Application2Employee,
    Application2Occupant,
    Employees,
    Event2Employee,
)


list_of_event_codes = []


def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> None:
    service_match = Services.filter_one(
        Services.service_name == "Super User",
        db=db_session,
    ).data
    for list_of_event_code in list_of_event_codes:
        created_service = Service2Events.find_or_create(
            service_id=service_match.id,
            service_uu_id=str(service_match.uu_id),
            event_id=list_of_event_code.id,
            event_uu_id=str(list_of_event_code.uu_id),
            is_confirmed=True,
            active=True,
            db=db_session,
        )
        if created_service.meta_data.created:
            created_service.save(db=db_session)
            print(
                f"UUID: {created_service.uu_id} event is saved to {service_match.uu_id}"
            )
            employee_added_service = Event2Employee.find_or_create(
                event_service_id=created_service.id,
                event_service_uu_id=str(created_service.uu_id),
                employee_id=super_user.id,
                employee_uu_id=str(super_user.uu_id),
                is_confirmed=True,
                db=db_session,
            )
            if employee_added_service.meta_data.created:
                employee_added_service.save(db=db_session)
                print(
                    f"UUID: {employee_added_service.uu_id} event is saved to {super_user.uu_id}"
                )
