#!/usr/bin/env python3
from __future__ import annotations

import argparse
import subprocess
import sys
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def _run(cmd: list[str]) -> int:
    proc = subprocess.run(cmd, check=False, cwd=ROOT)
    return proc.returncode


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--mode", choices=("release", "full"), default="release")
    args = ap.parse_args()
    checks = [
        [sys.executable, "tools/validate_specs.py"],
        [sys.executable, "tools/validate_gas_call_arity.py"],
        [sys.executable, "tools/validate_proposal_reference.py", "GatherTradingData.json", "--require"],
        [sys.executable, "tools/validate_harness_context.py", "GatherTradingData.json"],
    ]
    if args.mode == "full":
        checks.append([sys.executable, "tools/run_release_dag_v1.py", "--mode", "full"])
    else:
        checks.append([sys.executable, "tools/run_release_dag_v1.py", "--mode", "release"])
    rc = 0
    for cmd in checks:
        rc = _run(cmd)
        if rc != 0:
            break
    return rc


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