from typing import Union
from pathlib import Path


def _get_epoch_images(epoch_path: Union[str, Path],
                      image_type: str,
                      image_dir: str
                      ) -> list:
    """
    Get all available images in a given epoch.

    Args:
        epoch_path: Path to the epoch of interest.
        image_type: `COMBINED` or `TILES`.
        image_dir: The name of the folder containing the images to be updated.
            E.g. `STOKESI_IMAGES`.

    Returns:
        The list of images.

    Raises:
        Exception: Path does not exist.
    """

    P = Path(epoch_path) / image_type / image_dir
    if not P.exists():
        raise Exception("{} does not exist!".format(P))
    raw_images = sorted(list(P.glob("*.fits")))

    return raw_images