import configparser
import re


def _get_dict_cases(config_file, cases=('LAMMPS', 'GROMACS')):
    """
    Function to return a dictionary with regex patterns for the given cases and a rating of those.
    Reads in the config_file.

    Parameters
    ----------
    config_file : str or List[str]
        File path to the config file or a List of config files.
    cases : List[str] or Tuple[str]
        List of cases. Default is ``('LAMMPS', 'GROMACS')``.

    Returns
    -------
    dict_cases : dict[dict[unicode]]
        Dictionary of regex patterns for the different cases and a rating of those.
    """

    dict_cases = dict((case, dict()) for case in cases)

    if isinstance(config_file, (tuple, list)):
        for cfile in config_file:
            dict_cases.update(_get_dict_cases(cfile, cases=cases))
        return dict_cases

    # readin the config file
    config = configparser.ConfigParser(inline_comment_prefixes=';')
    config.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")
    config.read(config_file)

    for section in config.sections():
        for case in cases:
            if section.startswith(case):
                for key, value in config[section].items():
                    if key not in dict_cases[case]:
                        dict_cases[case][key] = int(value)
                    elif dict_cases[case][key] < value:
                        dict_cases[case][key] = int(value)

    return dict_cases