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

import argparse
from pathlib import Path

import yaml


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--strict", action="store_true")
    ap.add_argument("--path", default="governance/rule_lifecycle.yaml")
    args = ap.parse_args()
    data = yaml.safe_load(Path(args.path).read_text(encoding="utf-8"))
    ok = data.get("legacy_reference_blocked") is True and "active" in (data.get("statuses") or [])
    print("RULE_LIFECYCLE_POLICY_OK" if ok else "RULE_LIFECYCLE_POLICY_FAIL")
    print(yaml.safe_dump(data, sort_keys=False, allow_unicode=True).strip())
    return 0 if ok or not args.strict else 1


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