#!/usr/bin/env python3
from pathlib import Path
import json,sys
from gate_rules import validate_gate
HERE=Path(__file__).resolve().parent
RULES=json.loads((HERE/'CHECK_RULES.json').read_text(encoding='utf-8'))
if len(sys.argv)!=2:
    raise SystemExit('usage: python run_checks.py <gate-evidence.json>')
p=Path(sys.argv[1])
gate=json.loads(p.read_text(encoding='utf-8'))
errors=validate_gate(gate,RULES,HERE)
print(json.dumps({'status':'CONSISTENT' if not errors else 'INCONSISTENT','errors':errors},ensure_ascii=False,indent=2))
raise SystemExit(0 if not errors else 2)
