from typing import Dict
from typing import Any
from typing import Optional
from typing import Literal


def name(
    region: Dict[str, Any],
    sample: Dict[str, Any],
    systematic: Dict[str, Any],
    template: Optional[Literal["Up", "Down"]] = None,
) -> str:
    """Returns a unique name for each histogram.

    If the template is not None, the systematic is required to have a name (guaranteed
    as long as it follows the config schema).

    Args:
        region (Dict[str, Any]): containing all region information
        sample (Dict[str, Any]): containing all sample information
        systematic (Dict[str, Any]): containing all systematic information
        template (Optional[Literal["Up", "Down"]], optional): which template to
            consider: "Up", "Down", None for the nominal case, defaults to None

    Returns:
        str: unique name for the histogram
    """
    name = f"{region['Name']}_{sample['Name']}"
    if template is not None:
        name += f"_{systematic['Name']}_{template}"
    name = name.replace(" ", "-")
    return name