from web.services.web_service import WebService
from web.services.stats_service import StatsService
import json

def debug_roster():
    print("--- Debugging Roster Stats ---")
    lineups = WebService.get_lineups()
    if not lineups:
        print("No lineups found via WebService.")
        return

    raw_json = lineups[0]['player_ids_json']
    print(f"Raw JSON: {raw_json}")
    
    try:
        roster_ids = json.loads(raw_json)
        print(f"Parsed IDs (List): {roster_ids}")
        print(f"Type of first ID: {type(roster_ids[0])}")
    except Exception as e:
        print(f"JSON Parse Error: {e}")
        return

    target_id = roster_ids[0] # Pick first one
    print(f"\nTesting for Target ID: {target_id} (Type: {type(target_id)})")
    
    # Test StatsService
    dist = StatsService.get_roster_stats_distribution(target_id)
    print(f"\nDistribution Result: {dist}")
    
    # Test Basic Stats
    basic = StatsService.get_player_basic_stats(str(target_id))
    print(f"\nBasic Stats for {target_id}: {basic}")

if __name__ == "__main__":
    from web.app import create_app
    app = create_app()
    with app.app_context():
        debug_roster()