import logging


def update_params(class_params, flag_params, name="", print_params=False):
    """update a dictionary holding various parameters using a 'flag' containing a dictionary

    :param class_params: dictionary whose entries will get updated
    :param flag_params: dictionary used for the update (should only contain keys already present in `class_params`)
    :param name: string that will be printed if `print_params`=True
    :param print_params: boolean that decides if the available and updated params should be printed
    :return: updated dictionary `class_params`
    """
    if print_params:
        print("---{}---".format(name))
        print("available {}_params:".format(name))
        for i, j in enumerate(class_params):
            print("  {}: {}".format(j, class_params[j]))

        print("passed FLAGS.{}_params:".format(name))
        for i, j in enumerate(flag_params):
            print("  {}: {}".format(j, flag_params[j]))

    for i in flag_params:
        if i not in class_params:
            logging.critical("Given {0}_params-key '{1}' is not used by {0}-class!".format(name, i))

    class_params.update(flag_params)

    if print_params:
        print("updated {}_params:".format(name))
        for i, j in enumerate(class_params):
            print("  {}: {}".format(j, class_params[j]))

    return class_params