#!/usr/bin/env python3
"""Check a World.xyz market price against today's model prices.

Usage:
  python3 world_check.py "Team A vs Team B" <yes_price> [market]

market in: home_win, away_win, over_2_5, under_2_5, btts (default home_win)
Price: the YES price you see in Phantom (0-1, e.g. 0.55).

Prints an instant verdict (BUY YES / BUY NO / PASS) using the model price
from the latest pipeline run (world_prices.json).
"""
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from world import load_prices, find_match, verdict_for

if __name__ == "__main__":
    args = [a for a in sys.argv[1:] if not a.startswith("--")]
    if len(args) < 2:
        print(__doc__)
        sys.exit(1)
    match_key, raw_price = args[0], args[1]
    market = args[2] if len(args) > 2 else "home_win"
    try:
        price = float(raw_price)
    except ValueError:
        print(f"price must be a number 0-1, got '{raw_price}'")
        sys.exit(1)
    rows = load_prices()
    if not rows:
        print("No world_prices.json yet - run picks.py (pipeline) first.")
        sys.exit(1)
    row = find_match(rows, match_key)
    if not row:
        print(f"No match found for '{match_key}'. Available today:")
        for r in rows:
            print(f"  {r['home']} vs {r['away']}  ({r.get('league', '')})")
        sys.exit(1)
    for m in (market, "home_win", "away_win", "over_2_5", "btts"):
        if m in row["markets"]:
            print(verdict_for(row, m, price))
            break