#!/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/late_chase_attribution_v2.json")
    args = parser.parse_args()

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

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

    unlabeled_count = 0
    for ticker, info in attribution.items():
        if "distribution_risk" not in info or info["distribution_risk"] not in ("HIGH", "LOW"):
            unlabeled_count += 1

    if unlabeled_count > 0:
        print(f"Validation failed: {unlabeled_count} items with unlabeled distribution_risk")
        sys.exit(1)

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

if __name__ == "__main__":
    main()
