#!/usr/bin/env python3
from pathlib import Path
import json,sys
from gate_rules import validate_gate
HERE=Path(__file__).resolve().parent
if len(sys.argv)!=2:
    print('Usage: python run_checks.py evidence/your_matrix.json'); raise SystemExit(2)
try: gate=json.loads(Path(sys.argv[1]).read_text(encoding='utf-8')); rules=json.loads((HERE/'CHECK_RULES.json').read_text(encoding='utf-8'))
except Exception as e:
    print(json.dumps({'status':'INVALID_INPUT','error':str(e)},ensure_ascii=False,indent=2)); raise SystemExit(2)
errors=validate_gate(gate,rules,HERE)
print(json.dumps({'status':'CONSISTENT' if not errors else 'INCONSISTENT','error_count':len(errors),'errors':errors},ensure_ascii=False,indent=2))
raise SystemExit(0 if not errors else 1)
