from collections.abc import Iterable
from pathlib import Path

from accelforge.util._picklecache import PickleCache

TEST_PmappingGroup_DIR = Path(__file__).parent / "tmp" / "pmapping_cache"


def make_pmapping_pickle_cache(config_names: Iterable[str]) -> PickleCache:
    """
    Return a `PickleCache` using path generated by `make_pmapping_pickle_path`.
    """
    return PickleCache(make_pmapping_pickle_path(config_names))


def make_pmapping_pickle_path(config_names: Iterable[str]) -> Path:
    """
    Creates a path to a file in `TEST_PmappingGroup_DIR` with a file name that is
    `config_names` joined using "---" as separators.
    """
    pickle_name = "---".join(sorted(config_names)) + ".pkl"
    pickle_path = TEST_PmappingGroup_DIR / pickle_name
    return pickle_path
