"""
Test BasicProcessor implementation
"""

import sqlite3
import sys
import os

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

from database.L3.processors import BasicProcessor

def test_basic_processor():
    """Test BasicProcessor on a real player from L2"""
    
    # Connect to L2 database
    l2_path = os.path.join(os.path.dirname(__file__), '..', 'L2', 'L2.db')
    conn = sqlite3.connect(l2_path)
    
    try:
        # Get a test player
        cursor = conn.cursor()
        cursor.execute("SELECT steam_id_64 FROM dim_players LIMIT 1")
        result = cursor.fetchone()
        
        if not result:
            print("No players found in L2 database")
            return False
        
        steam_id = result[0]
        print(f"Testing BasicProcessor for player: {steam_id}")
        
        # Calculate features
        features = BasicProcessor.calculate(steam_id, conn)
        
        print(f"\n✓ Calculated {len(features)} features")
        print(f"\nSample features:")
        print(f"  core_avg_rating: {features.get('core_avg_rating', 0)}")
        print(f"  core_avg_kd: {features.get('core_avg_kd', 0)}")
        print(f"  core_total_kills: {features.get('core_total_kills', 0)}")
        print(f"  core_win_rate: {features.get('core_win_rate', 0)}")
        print(f"  core_top_weapon: {features.get('core_top_weapon', 'unknown')}")
        
        # Verify we have all 41 features
        expected_count = 41
        if len(features) == expected_count:
            print(f"\n✓ Feature count correct: {expected_count}")
            return True
        else:
            print(f"\n✗ Feature count mismatch: expected {expected_count}, got {len(features)}")
            return False
            
    finally:
        conn.close()

if __name__ == "__main__":
    success = test_basic_processor()
    sys.exit(0 if success else 1)
