#!/usr/bin/env python3
"""Test script to check backend API endpoint directly"""
import os
import sys
import json
from dotenv import load_dotenv

# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

load_dotenv()

# Import Flask app
from needle.app import app

print("Testing backend API endpoint...")
print("="*60)

with app.test_client() as client:
    response = client.get('/api/status')
    if response.status_code == 200:
        data = json.loads(response.data)
        
        # Find Kansas
        print("\nSearching for Kansas...")
        for conference, teams in data.get('teams_by_conference', {}).items():
            for team in teams:
                if team.get('team') == 'Kansas':
                    print(f"\nFound Kansas in {conference}:")
                    print(f"  Record: {team.get('record')}")
                    print(f"  Expected wins: {team.get('expected_wins')}")
                    print(f"  Status: {team.get('status')}")
                    
                    # Check upcoming games
                    upcoming = team.get('upcoming_games', [])
                    print(f"\n  Upcoming games ({len(upcoming)}):")
                    for game in upcoming:
                        if 'Utah' in str(game.get('away_team', '')) or 'Utah' in str(game.get('home_team', '')):
                            print(f"    Game vs Utah:")
                            print(f"      Home: {game.get('home_team')}")
                            print(f"      Away: {game.get('away_team')}")
                            print(f"      Home win prob: {game.get('home_win_prob')}")
                            print(f"      Away win prob: {game.get('away_win_prob')}")
                            print(f"      Clock: {game.get('clock')}")
                            print(f"      Period: {game.get('period')}")
                            print(f"      Completed: {game.get('completed')}")
                    break
        
        # Also check expected eligible
        print(f"\n\nExpected eligible teams: {data.get('expected_eligible')}")
        print(f"Currently eligible: {data.get('currently_eligible')}")
        
    else:
        print(f"Error: HTTP {response.status_code}")
        print(response.data.decode('utf-8'))

