"""Benchmark orchestrator."""

from __future__ import annotations

from pathlib import Path

import pandas as pd

from babappa.benchmark.real_data import run_real_data_benchmark
from babappa.benchmark.simulation import run_simulation_benchmark
from babappa.config import BABAPPAConfig
from babappa.workflow import profile_callable


def run_all_benchmarks(cfg: BABAPPAConfig, outdir: str | Path, seed: int) -> dict[str, pd.DataFrame]:
    out = Path(outdir)
    out.mkdir(parents=True, exist_ok=True)

    sim_res, sim_prof = profile_callable(
        run_simulation_benchmark,
        cfg,
        out / "simulation",
        seed,
        16,
    )
    real_res, real_prof = profile_callable(run_real_data_benchmark, cfg, out / "real_data", seed + 7)

    profile = pd.DataFrame(
        [
            {"track": "simulation", **sim_prof},
            {"track": "real_data", **real_prof},
        ]
    )
    profile.to_csv(out / "runtime_profile.tsv", sep="\t", index=False)

    return {"simulation": sim_res, "real_data": real_res}
