"""Metadata loading utilities."""

from __future__ import annotations

from pathlib import Path

import pandas as pd


def read_metadata(path: str | Path | None) -> pd.DataFrame | None:
    if path is None:
        return None
    in_path = Path(path)
    if not in_path.exists():
        raise FileNotFoundError(f"Metadata file not found: {in_path}")
    suffix = in_path.suffix.lower()
    if suffix == ".csv":
        return pd.read_csv(in_path)
    if suffix in {".tsv", ".txt"}:
        return pd.read_csv(in_path, sep="\t")
    raise ValueError("Metadata must be CSV or TSV")
