#!/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("--matrix", default="governance/authority_matrix.yaml")
    args = ap.parse_args()
    data = yaml.safe_load(Path(args.matrix).read_text(encoding="utf-8"))
    owned_pct = float(data.get("owned_output_field_pct") or 0)
    collision_count = data.get("authority_collision_count")
    ok = owned_pct >= 100.0 and int(collision_count if collision_count is not None else 1) == 0
    print(f"AUTHORITY_MATRIX_{'OK' if ok else '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())
