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

ROOT = Path(__file__).resolve().parents[1]

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--json", default="Temp/engine_health_card_v1.json")
    args = parser.parse_args()

    json_path = ROOT / args.json
    if not json_path.exists():
        print(f"Health card file not found: {json_path}")
        sys.exit(1)

    data = json.loads(json_path.read_text(encoding="utf-8"))
    card = data.get("health_card", {})

    # Check field count constraint
    if len(card) > 25:
        print(f"Validation failed: health_card_field_count={len(card)} exceeds limit of 25")
        sys.exit(1)

    # Check next_action presence
    if "next_action" not in card or not card["next_action"]:
        print("Validation failed: missing next_action in health_card")
        sys.exit(1)

    print("VALIDATION OK")
    sys.exit(0)

if __name__ == "__main__":
    main()
