import yaml


def parse_config(file_list):
    """
    Parse required options from a list of configuration files

    :param file_list: list
        list of config files to parse
    :return: tuple
        Dictionaries of the required simulation inputs
    """

    corsika_dict = dict()
    simulation_input = dict()
    fit_input = dict()
    telescope_input = dict()

    # Loop over input config files
    for f in file_list:
        # Open YAML file
        with open(f[0],"r") as yaml_file:
            yaml_file = yaml.safe_load(yaml_file)

        # Get the config options if they exist
        if "CORSIKA" in yaml_file:
            corsika_dict.update(yaml_file["CORSIKA"])
        if "ShowerSimulation" in yaml_file:
            simulation_input.update(yaml_file["ShowerSimulation"])
        if "TelescopeSimulation" in yaml_file:
            telescope_input.update(yaml_file["TelescopeSimulation"])
        if "Fit" in yaml_file:
            fit_input.update(yaml_file["Fit"])

    return corsika_dict, simulation_input, telescope_input, fit_input