from typing import Union
from typing import List


def build_gcm_identifier(
    gcm: str,
    scenario: str,
    train_period_start: str,
    train_period_end: str,
    predict_period_start: str,
    predict_period_end: str,
    variables: Union[str, List[str]],
    **kwargs,
) -> str:
    """
    Build the common identifier for GCM related data

    Parameters
    ----------
    gcm : str
        From run hyperparameters
    scenario : str
        From run hyperparameters
    train_period_start : str
        From run hyperparameters
    train_period_end : str
        From run hyperparameters
    predict_period_start : str
        From run hyperparameters
    predict_period_end : str
        From run hyperparameters
    variables : str
        From run hyperparameters

    Returns
    -------
    identifier : str
        string to be used in gcm related paths as specified by the params
    """
    if isinstance(variables, str):
        variables = [variables]
    var_string = '_'.join(variables)
    return f'{gcm}_{scenario}_{train_period_start}_{train_period_end}_{predict_period_start}_{predict_period_end}_{var_string}'