from pathlib import Path
from typing import Any
import yaml


def hepdata(
    rex_dir: str | Path,
    region: str,
    stage: str = "pre",
) -> dict[Any, Any]:
    """Parse HEPData information.

    Parameters
    ----------
    rex_dir : str or pathlib.Path
        Path of the TRExFitter result directory
    region : str
        Region to get histograms for
    stage : str
        Fitting stage (`"pre"` or `"post"`).

    """
    yaml_path = Path(rex_dir) / "Plots" / f"{region}_{stage}fit.yaml"
    return yaml.full_load(yaml_path.read_text())