#!/usr/bin/env python3
"""
Simple test script to verify CFBD API connection and basic functionality
"""
import os
from dotenv import load_dotenv
import cfbd

load_dotenv()

def test_cfbd_connection():
    """Test basic CFBD API connection"""
    api_key = os.getenv('CFBD_API_KEY', '')
    
    if not api_key:
        print("❌ ERROR: CFBD_API_KEY not found in .env file")
        return False
    
    print(f"✓ API Key found: {api_key[:10]}...")
    
    try:
        configuration = cfbd.Configuration(access_token=api_key)
        api_client = cfbd.ApiClient(configuration)
        
        # Test fetching teams
        teams_api = cfbd.TeamsApi(api_client)
        print("Testing API connection...")
        
        # Get FBS teams
        teams = teams_api.get_fbs_teams()
        
        print(f"✓ Successfully fetched {len(teams)} FBS teams")
        
        # Show a few examples
        print("\nSample teams:")
        for i, team in enumerate(teams[:5]):
            if hasattr(team, 'school'):
                print(f"  - {team.school}")
            elif hasattr(team, 'team'):
                print(f"  - {team.team}")
        
        return True
        
    except Exception as e:
        print(f"❌ ERROR: {e}")
        return False

if __name__ == '__main__':
    print("Testing CFBD API Setup\n")
    success = test_cfbd_connection()
    
    if success:
        print("\n✓ Setup looks good! You can now run: python app.py")
    else:
        print("\n❌ Setup failed. Please check your API key and try again.")

