#!/usr/bin/env python3
"""
Test to see what legitimate hyphenated artists exist in the database.
"""

import psycopg2
import psycopg2.extras

# Database configuration
DB_HOST = "172.18.0.2"
DB_PORT = 5432
DB_NAME = "musicbrainz_db"
DB_USER = "musicbrainz"
DB_PASSWORD = "musicbrainz"

def test_hyphenated_artists():
    """Test hyphenated artists in the database."""
    print("🔍 Testing hyphenated artists in the database...")
    
    try:
        connection = psycopg2.connect(
            host=DB_HOST,
            port=DB_PORT,
            database=DB_NAME,
            user=DB_USER,
            password=DB_PASSWORD,
            connect_timeout=10
        )
        cursor = connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
        
        print("✅ Connected to database")
        
        # Find artists with hyphens
        print("\n1. Artists with hyphens (first 20):")
        cursor.execute("SELECT name, gid FROM artist WHERE name LIKE '%-%' LIMIT 20")
        hyphenated = cursor.fetchall()
        
        for artist in hyphenated:
            print(f"     {artist['name']} (MBID: {artist['gid']})")
        
        # Test specific cases
        test_cases = [
            "Eazy-E",
            "AC-DC", 
            "D-A-D",
            "E-40",
            "M-1",
            "T-Pain"
        ]
        
        print(f"\n2. Testing specific hyphenated artists:")
        for test_case in test_cases:
            print(f"\n   Testing: {test_case}")
            
            # Exact match
            cursor.execute("SELECT name, gid FROM artist WHERE name = %s LIMIT 1", (test_case,))
            exact = cursor.fetchone()
            if exact:
                print(f"     Exact match: {exact['name']} (MBID: {exact['gid']})")
            else:
                print(f"     No exact match")
            
            # Case-insensitive match
            cursor.execute("SELECT name, gid FROM artist WHERE LOWER(name) = LOWER(%s) LIMIT 1", (test_case,))
            case_insensitive = cursor.fetchone()
            if case_insensitive:
                print(f"     Case-insensitive match: {case_insensitive['name']} (MBID: {case_insensitive['gid']})")
            else:
                print(f"     No case-insensitive match")
            
            # ILIKE match
            cursor.execute("SELECT name, gid FROM artist WHERE name ILIKE %s LIMIT 3", (f"%{test_case}%",))
            ilike_matches = cursor.fetchall()
            print(f"     ILIKE matches ({len(ilike_matches)}):")
            for match in ilike_matches:
                print(f"       {match['name']} (MBID: {match['gid']})")
        
        cursor.close()
        connection.close()
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_hyphenated_artists() 