#!/usr/bin/env python3
import json
import sys
from pathlib import Path
from pack_rules import validate_pack

HERE = Path(__file__).resolve().parent


def main() -> int:
    if len(sys.argv) != 2:
        print("usage: python run_checks.py PATH_TO_EVIDENCE_PACK.json")
        return 2
    path = Path(sys.argv[1])
    pack = json.loads(path.read_text(encoding="utf-8"))
    rules = json.loads((HERE / "CHECK_RULES.json").read_text(encoding="utf-8"))
    errors = validate_pack(pack, rules)
    if errors:
        print(json.dumps({"status":"INCONSISTENT","approval":False,"errors":errors,"note":"Checker consistency is not a hidden answer or human approval."}, ensure_ascii=False, indent=2))
        return 1
    print(json.dumps({"status":"CONSISTENT","approval":False,"errors":[],"note":"Internal consistency only. A human reviewer must reconstruct the decision from visible evidence."}, ensure_ascii=False, indent=2))
    return 0


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