from pathlib import Path


def get_pose_path(video_path: Path):
    """
    take a path to a video file and return the path to the corresponding
    pose_est h5 file
    :param video_path: Path to video file in project
    :return: Path object representing location of corresponding pose_est h5 file
    :raises ValueError: if video_path does not have corresponding pose_est file
    """

    file_base = video_path.with_suffix('')

    # default to the highest version pose file for a video
    if video_path.with_name(file_base.name + '_pose_est_v5.h5').exists():
        return video_path.with_name(file_base.name + '_pose_est_v5.h5')
    elif video_path.with_name(file_base.name + '_pose_est_v4.h5').exists():
        return video_path.with_name(file_base.name + '_pose_est_v4.h5')
    elif video_path.with_name(file_base.name + '_pose_est_v3.h5').exists():
        return video_path.with_name(file_base.name + '_pose_est_v3.h5')
    elif video_path.with_name(file_base.name + '_pose_est_v2.h5').exists():
        return video_path.with_name(file_base.name + '_pose_est_v2.h5')
    else:
        raise ValueError("Video does not have pose file")