import toml


def get_original_toml_settings(toml_file_path):
    """
    Get the original settings from the toml file. Conditions, Caller settings, conditions.classified and conditions.unclassified
    Parameters
    ----------
    toml_file_path: pathlib.Path
        Path to the toml file that will be updated
    Returns
    -------
    dict
        Dict of the settings we will keep between iterations
    """
    with open(toml_file_path, "r") as fh:
        dicty = toml.load(fh)
    keys = {"classified", "unclassified"}
    toml_dict = {"caller_settings": dicty["caller_settings"]}
    # nested dictionary conditions faff
    generic_conditions = {k: v for k, v in dicty["conditions"].items() if not isinstance(v, dict)}
    base_conditions = {k: v for k, v in dicty["conditions"].items() if isinstance(v, dict) and k in keys}
    other_conditions = {k: v for k, v in dicty["conditions"].items() if isinstance(v, dict) and k not in keys}
    toml_dict["conditions"] = generic_conditions
    toml_dict["conditions"].update(base_conditions)
    return toml_dict, other_conditions