from __future__ import annotations

import argparse
import json
from pathlib import Path


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--plan", required=True)
    args = ap.parse_args()
    plan = json.loads(Path(args.plan).read_text(encoding="utf-8"))
    ok = (
        plan.get("active_count_per_formula") == 1
        and plan.get("report_legacy_direct_read_count") == 0
        and plan.get("authority_collision_count") == 0
    )
    print(json.dumps({
        "formula_id": "ARTIFACT_RETIREMENT_PLAN_V1_VALIDATION",
        "gate": "PASS" if ok else "FAIL",
        "active_count_per_formula": plan.get("active_count_per_formula", 0),
        "report_legacy_direct_read_count": plan.get("report_legacy_direct_read_count", -1),
        "authority_collision_count": plan.get("authority_collision_count", -1),
    }, ensure_ascii=True, indent=2))
    return 0 if ok else 1


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