import logging


def project_exists_firebase(project_id, firebase):
    """
    The function to check whether a project exists in firebase.

    Parameters
    ----------
    project_id : int
        the id of the project
    firebase : pyrebase firebase object
        initialized firebase app with admin authentication

    Returns
    -------
    bool
        True if project info and group info exist in firebase, false otherwise
    """

    fb_db = firebase.database()
    project_data = fb_db.child("projects").child(project_id).get().val()

    if not project_data:
        logging.warning('%s - project_exists_firebase - project info NOT in firebase' % project_id)
    else:
        logging.warning('%s - project_exists_firebase - project info in firebase' % project_id)

    groups_data = fb_db.child("groups").child(project_id).shallow().get().val()
    if not groups_data:
        logging.warning('%s - project_exists_firebase - groups info NOT in firebase' % project_id)
    else:
        logging.warning('%s - project_exists_firebase - groups info in firebase' % project_id)

    if project_data and groups_data:
        return True
    else:
        return False