from __future__ import annotations

import argparse
import json

from .corpus import registered_asset_report
from .gate_c import analyze_gate_c, gate_c_readiness
from .run_store import create_run, finalize_run, get_run, list_runs


def main() -> None:
    parser = argparse.ArgumentParser(description="GAL-FINGERPRINT-I Gate C chamber controller")
    sub = parser.add_subparsers(dest="command", required=True)
    sub.add_parser("validate")
    sub.add_parser("list-runs")
    create = sub.add_parser("create-run")
    create.add_argument("--mode", required=True)
    show = sub.add_parser("show-run")
    show.add_argument("run_id")
    finalize = sub.add_parser("finalize")
    finalize.add_argument("run_id")
    sub.add_parser("gate-c-readiness")
    sub.add_parser("gate-c")
    args = parser.parse_args()

    if args.command == "validate":
        print(json.dumps(registered_asset_report(), indent=2))
    elif args.command == "list-runs":
        print(json.dumps(list_runs(), indent=2))
    elif args.command == "create-run":
        print(json.dumps(create_run(args.mode), indent=2))
    elif args.command == "show-run":
        print(json.dumps(get_run(args.run_id), indent=2))
    elif args.command == "finalize":
        print(json.dumps(finalize_run(args.run_id), indent=2))
    elif args.command == "gate-c-readiness":
        print(json.dumps(gate_c_readiness(), indent=2))
    elif args.command == "gate-c":
        print(json.dumps(analyze_gate_c(), indent=2))


if __name__ == "__main__":
    main()
