from pathlib import Path


def validate_scene_path(scene_path) -> str:
    """
    Checks if a path looks like a Scanner directory. Returns a fixed path, if for example the path
    refers to a subfile or directory in the scene folder. If scene_path is an actual scene path, then
    this is an identity function.

    throws ValueError if this doesn't look to be a scene folder.

    scene_path: str path to a potential path
    returns: str scene_path or fixed scene_path
    """
    def looks_like_scanner_scene(path):
        is_dir = path.is_dir()
        has_rgb = (path / "rgb.mp4").is_file()
        has_depth = (path / "depth").is_dir()
        has_intrinsics = (path / "camera_matrix.csv").is_file()
        return is_dir and has_rgb and has_depth and has_intrinsics

    path = Path(scene_path)
    if looks_like_scanner_scene(path):
        return scene_path
    elif looks_like_scanner_scene(path.parent):
        return str(path.parent)
    elif looks_like_scanner_scene(path.parent.parent):
        return str(path.parent.parent)
    raise ValueError(scene_path)