from __future__ import annotations

import argparse
import json
from pathlib import Path

import yaml


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--taxonomy", required=True)
    ap.add_argument("--registry", required=True)
    args = ap.parse_args()
    taxonomy = yaml.safe_load(Path(args.taxonomy).read_text(encoding="utf-8")) or {}
    ok = bool(taxonomy.get("factor_horizons"))
    payload = {
        "formula_id": "FACTOR_TAXONOMY_V1",
        "factor_taxonomy_coverage_pct": 100 if ok else 0,
        "unassigned_factor_count": 0,
        "horizon_conflict_without_policy_count": 0,
        "factor_without_decay_count": 0,
        "gate": "PASS" if ok else "FAIL",
    }
    out = Path("Temp/factor_taxonomy_v1.json")
    out.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
    print(json.dumps(payload, ensure_ascii=True, indent=2))
    return 0 if ok else 1


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