"""Quick test: V20+Quant integration — EV Edge, Kelly staking, edge-based grading."""
import json
from services.single_match_orchestrator import SingleMatchOrchestrator

MATCH_IDS = [
    "er7n8hqndkhvdsg6an72r7h90",  # Def. Justicia vs Atl Lanus
    "etpay8k4qr3gts3jjidfebaxg",  # CA Tigre vs Gymnasia
]

o = SingleMatchOrchestrator()

for mid in MATCH_IDS:
    print(f"\n{'='*60}")
    print(f"MATCH: {mid}")
    print(f"{'='*60}")
    r = o.analyze_match(mid)
    if not r:
        print("  Match not found")
        continue

    info = r.get("match_info", {})
    print(f"  {info.get('match_name', '?')} | {info.get('league', '?')}")

    mp = r.get("main_pick", {})
    print(f"\n  MAIN PICK: {mp.get('market')} {mp.get('pick')}")
    print(f"    probability:  {mp.get('probability', 0):.4f}")
    print(f"    odds:         {mp.get('odds', 0):.2f}")
    print(f"    ev_edge:      {mp.get('ev_edge', mp.get('edge', 0)):+.4f}")
    print(f"    implied_prob: {mp.get('implied_prob', 0):.4f}")
    print(f"    bet_grade:    {mp.get('bet_grade', 'N/A')}")
    print(f"    stake_units:  {mp.get('stake_units', 0)}")
    print(f"    playable:     {mp.get('playable', False)}")
    print(f"    reasons:      {mp.get('decision_reasons', [])}")

    print(f"\n  ALL MARKETS (with EV Edge + Kelly):")
    for b in r.get("bet_summary", []):
        ev = b.get("ev_edge", 0)
        imp = b.get("implied_prob", 0)
        flag = ">>>" if b.get("playable") else "   "
        mkt = b["market"]
        pick = b["pick"]
        odds = b.get("odds", 0)
        grade = b["bet_grade"]
        stake = b["stake_units"]
        conf = b.get("calibrated_confidence", 0)
        print(
            f"    {flag} {mkt:8s} {pick:12s} "
            f"ev_edge={ev:+.3f}  "
            f"odds={odds:.2f}  "
            f"stake={stake:.1f}  "
            f"grade={grade:4s}  "
            f"conf={conf:.1f}%  "
            f"implied={imp:.3f}"
        )

    print()
