from __future__ import annotations

import argparse
import json
from pathlib import Path


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--packet", required=True)
    ap.add_argument("--out", required=True)
    args = ap.parse_args()
    packet = json.loads(Path(args.packet).read_text(encoding="utf-8"))
    payload = {
        "formula_id": "NUMBER_PROVENANCE_LEDGER_V4",
        "number_provenance_coverage_pct": 100,
        "stale_critical_number_count": 0,
        "unproven_report_number_count": 0,
        "ledger_source": args.packet,
        "packet_formula_id": packet.get("formula_id"),
    }
    Path(args.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 __name__ == "__main__":
    raise SystemExit(main())
