import logging


def delete_firebase_results(firebase, all_results):
    """
    The function to delete all results in firebase

    Parameters
    ----------
    firebase : pyrebase firebase object
        initialized firebase app with admin authentication
    results : dict
        The results in a dictionary with the following format:
        {
        "task_id": {
            "user1_id": {},
            "user2_id": {},
            }
        }

    Returns
    -------
    bool
        True if successful, False otherwise

    Notes
    -----
    We use the update method of firebase instead of delete.
    Update allows to delete items at multiple locations at the same time.
    """

    fb_db = firebase.database()
    # we will use multilocation update to deete the entries
    # therefore we crate an dict with the items we want to delete
    data = {}
    for task_id, results in all_results.items():
        for child_id, result in results.items():
            key = 'results/{task_id}/{child_id}'.format(
                task_id=task_id,
                child_id=child_id)

            data[key] = None

    fb_db.update(data)
    del fb_db

    logging.warning('ALL - delete_firebase_results - deleted all results in firebase')
    return True