"""Dataset combination utilities."""

from __future__ import annotations

from pathlib import Path
from typing import Dict, Iterable, Optional

from any4robot.lerobot import DatasetOperations


def merge_lerobot_datasets(
    source_datasets: Iterable[str | Path],
    output_path: str | Path,
    task_mapping: Optional[Dict[str, str]] = None,
    dry_run: bool = False,
) -> bool:
    """
    Merge multiple LeRobot datasets into a single dataset.

    This delegates to the LERO DatasetOperations merge implementation.
    """
    source_paths = [Path(p) for p in source_datasets]
    output = Path(output_path)

    if not source_paths:
        raise ValueError("source_datasets must contain at least one dataset path")

    # Use the first dataset path to bootstrap operations for merging.
    ops = DatasetOperations(source_paths[0])
    return ops.merge_datasets(source_paths, output, task_mapping=task_mapping, dry_run=dry_run)


__all__ = ["merge_lerobot_datasets"]
