from __future__ import annotations

import argparse
from pathlib import Path
import subprocess
import sys

ROOT = Path(__file__).resolve().parents[1]
DEFAULT_OUT = ROOT / "Temp" / "formula_behavioral_coverage_v3.json"


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--strict", action="store_true")
    ap.add_argument("--out", default=str(DEFAULT_OUT))
    args = ap.parse_args()

    cmd = [sys.executable, str(ROOT / "tools" / "run_formula_golden_cases_v2.py")]
    if args.strict:
        cmd.append("--strict")
    rc = subprocess.run(cmd, cwd=ROOT).returncode
    src = ROOT / "Temp" / "formula_behavioral_coverage_v1.json"
    dst = Path(args.out)
    if not dst.is_absolute():
        dst = ROOT / dst
    if src.exists():
        dst.write_text(src.read_text(encoding="utf-8"), encoding="utf-8")
    print(f"RUN_FORMULA_GOLDEN_CASES_V3 rc={rc} out={dst}")
    return rc


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