from __future__ import annotations

import argparse
import json
import re
from pathlib import Path


NUM_RE = re.compile(r"(?<![\w.])(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?")


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--report", required=True)
    parser.add_argument("--packet", required=True)
    parser.add_argument("--strict", action="store_true")
    args = parser.parse_args()
    report = Path(args.report).read_text(encoding="utf-8")
    packet = json.loads(Path(args.packet).read_text(encoding="utf-8"))
    source_count = sum(1 for _ in NUM_RE.finditer(report))
    provenance_count = report.count("source_ref") + report.count("formula_id")
    if source_count == 0 or provenance_count == 0:
        print("FAIL")
        return 1
    print("NUMBER_PROVENANCE_OK")
    print(f"report_numbers={source_count}")
    print(f"provenance_markers={provenance_count}")
    return 0


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

