"""
Test script for MySQL functionality.
Run this to verify your MySQL setup is working correctly.
"""

def test_mysql_connection():
    """Test basic MySQL connection and operations."""
    try:
        from mysql.mysql_client import (
            save_playlist_to_mysql,
            get_playlist_names_from_mysql,
            playlist_name_exists_in_mysql
        )        
        
        # Test saving a playlist
        test_playlist = "Test Playlist"
        result = save_playlist_to_mysql(test_playlist)
        
        if result.get('error'):
            print(f"❌ Error saving playlist: {result['error']}")
            return False
        
        print(f"✅ Saved playlist: {test_playlist}")
        
        # Test fetching playlists
        playlists = get_playlist_names_from_mysql()
        print(f"✅ Fetched {len(playlists)} playlists: {playlists}")
        
        # Test checking existence
        exists = playlist_name_exists_in_mysql(test_playlist)
        print(f"✅ Playlist exists check: {exists}")
        
        print("\n🎉 All tests passed! MySQL is working correctly.")
        return True
        
    except ImportError as e:
        print(f"❌ Import error: {e}")
        print("Make sure you've installed the required dependencies:")
        print("pip install mysql-connector-python python-dotenv")
        return False
        
    except Exception as e:
        print(f"❌ Error during testing: {e}")
        print("Check your MySQL configuration and .env file")
        return False

if __name__ == "__main__":
    print("🚀 Testing MySQL Connection and Operations")
    print("=" * 50)
    
    success = test_mysql_connection()
    
    if success:
        print("\n✅ MySQL setup is working correctly!")
    else:
        print("\n❌ MySQL setup needs attention. Check the error messages above.")