"""Weight download utilities using HuggingFace Hub."""

from pathlib import Path
from huggingface_hub import hf_hub_download


def download_weights(
    repo_id: str,
    filenames: list[str],
    token: str | None = None,
) -> Path:
    """Download model weights from HuggingFace and return the cache directory.

    Files are cached locally after first download — subsequent calls are instant.
    """
    print("Loading model weights...")
    paths = []
    for filename in filenames:
        path = hf_hub_download(repo_id=repo_id, filename=filename, token=token)
        paths.append(Path(path))

    # Return the parent directory containing all downloaded files
    # HuggingFace caches them in a consistent snapshot directory
    return paths[0].parent
