"""CLI dispatcher for dashboard producers.

  python -m training.producers replay   --episode … --host-id …
  python -m training.producers metrics  --window … --schema …
  python -m training.producers perf     --window … --schema …
  python -m training.producers profiles --validation … --store …

Each subcommand forwards remaining argv to the matching module's main().
"""
from __future__ import annotations

import sys


SUBCOMMANDS = {
    "replay":   "training.producers.replay",
    "metrics":  "training.producers.metrics",
    "perf":     "training.producers.perf",
    "profiles": "training.producers.profiles",
}


def main() -> int:
    if len(sys.argv) < 2 or sys.argv[1] in {"-h", "--help"}:
        print("usage: python -m training.producers "
              "<replay|metrics|perf|profiles> [args]", file=sys.stderr)
        return 2
    sub = sys.argv[1]
    if sub not in SUBCOMMANDS:
        print(f"unknown subcommand: {sub}", file=sys.stderr)
        return 2
    import importlib
    mod = importlib.import_module(SUBCOMMANDS[sub])
    sys.argv = [f"{sys.argv[0]} {sub}"] + sys.argv[2:]
    return int(mod.main() or 0)


if __name__ == "__main__":
    raise SystemExit(main())
