import os
from pathlib import Path


def validate_exists(fpath: Path):
    if not fpath.exists():
        raise FileNotFoundError(f"Should exist but not: {fpath}")


def read_lines(fp: Path | str):
    fp = Path(fp)
    lines = fp.read_text().strip().splitlines()
    return lines


def get_relative_subpath(base_dir, full_path):
    """deepseek
    Returns the relative path only if full_path is inside base_dir.
    """
    base_dir = os.path.abspath(base_dir)
    full_path = os.path.abspath(full_path)

    try:
        relative = os.path.relpath(full_path, start=base_dir)
        if relative.startswith(".."):
            raise ValueError(f"Path {full_path} is not under base directory {base_dir}")
        return relative
    except ValueError:
        # Handle case where paths are on different drives (Windows)
        raise ValueError(f"Cannot get relative path between {base_dir} and {full_path}")
