from pathlib import Path
from typing import Optional


def load_latest_model(model_folder: Path) -> Optional[Path]:
    """Finds the latest model inside the folder where
    all the models are saved

    Args:
        model_folder (Path): folder containing the models

    Returns:
        Path: file path of the most recent model
    """

    model_cps = [
        filename
        for filename in model_folder.parent.iterdir()
        if filename.name.startswith(model_folder.name)
    ]

    if len(model_cps) == 0:
        return None

    return sorted(model_cps)[-1]