import yaml
from pathlib import Path


def load_config(config_file):
    """
    Load configuration from a YAML file.
    Parameters
    ----------
    config_file : str
        Path to the YAML configuration file.
    Returns
    -------
    dict
        Dictionary containing the configuration parameters.
    """
    
    with open(config_file, "r") as file:
        config = yaml.safe_load(file)
    return config


def save_config(config, config_file):
    """
    Save the configuration dictionary to a YAML file.
    Parameters
    ----------
    config : dict
        The configuration dictionary to be saved.
    config_file : str
        The path to the file where the configuration will be saved.
    Returns
    -------
    None
    """

    with open(config_file, "w") as file:
        yaml.dump(config, file)
    return


def get_output_dir(config):
    """
    Constructs the output directory path based on the given configuration.
    Parameters
    ----------
    config : dict
        A dictionary containing configuration parameters. It must include:
        - "output_dir" : str
            The base directory where outputs should be stored.
        - "exp_name" : str
            The name of the experiment, which will be used as a subdirectory.
    Returns
    -------
    Path
        A Path to the output directory.
    """

    return Path(config["output_dir"], config["exp_name"])

