from typing import List
from typing import Tuple


def retrieve_parameters(
    mdp_name: str,
    mdp_prms: str,
    agent_name: str,
    agent_prms: str,
    config_files: List[str],
) -> Tuple[List[str], List[str]]:
    """

    Parameters
    ----------
    mdp_name: str.
        the name of the MDP family.
    mdp_prms: str.
        the string identifying the configuration of the MDP, e.g. 'prms_0'.
    agent_name: str.
        the name of the agent class.
    agent_prms: str.
        the string identifying the configuration of the agent, e.g. 'prms_0'.
    config_files: List[str].
        the gin configuration files paths.

    Returns
    -------
    the gin configuration of the MDP and the agent.
    """
    with open(next(filter(lambda x: mdp_name in x, config_files)), "r") as f:
        mdp_parameters = list(
            map(
                lambda x: x.replace(mdp_prms + "/", "")
                .replace("\n", "")
                .replace(mdp_name + ".", ""),
                filter(lambda x: mdp_prms in x, f.readlines()),
            )
        )
    with open(next(filter(lambda x: agent_name in x, config_files)), "r") as f:
        agent_parameters = list(
            map(
                lambda x: x.replace(agent_prms + "/", "")
                .replace("\n", "")
                .replace(agent_name + ".", ""),
                filter(lambda x: agent_prms in x, f.readlines()),
            )
        )
    return mdp_parameters, agent_parameters