"""Shared utilities for CLI commands."""

from __future__ import annotations

import sys
from pathlib import Path


def resolve_csv_files(path: Path) -> list[Path] | None:
    """Resolve CSV files from a path (file or directory).

    Returns a sorted list of CSV paths, or None on error (after printing).
    """
    if path.is_dir():
        csv_files = sorted(path.glob('*.csv'))
        if not csv_files:
            print(f'error: no CSV files found in {path}', file=sys.stderr)
            return None
        return csv_files

    if path.suffix.lower() == '.csv':
        return [path]

    print(f'error: {path} is not a CSV file', file=sys.stderr)
    return None
