#!/usr/bin/env python3
"""
Test specifically for Blink-182.
"""

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_blink182():
    """Test Blink-182 specifically."""
    print("🔍 Testing Blink-182 specifically...")
    
    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")
        
        # Test 1: Search for Blink-182
        print("\n1. Searching for 'Blink-182'...")
        cursor.execute("SELECT name, gid FROM artist WHERE name = 'Blink-182' LIMIT 5")
        blink182_results = cursor.fetchall()
        print(f"   Found {len(blink182_results)} exact matches:")
        for result in blink182_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 2: Case-insensitive search
        print("\n2. Case-insensitive search for 'blink-182'...")
        cursor.execute("SELECT name, gid FROM artist WHERE LOWER(name) = LOWER('Blink-182') LIMIT 5")
        blink182_ci_results = cursor.fetchall()
        print(f"   Found {len(blink182_ci_results)} case-insensitive matches:")
        for result in blink182_ci_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 3: Fuzzy search
        print("\n3. Fuzzy search for 'Blink-182'...")
        cursor.execute("SELECT name, gid FROM artist WHERE name ILIKE '%Blink%' OR name ILIKE '%182%' LIMIT 10")
        fuzzy_results = cursor.fetchall()
        print(f"   Found {len(fuzzy_results)} fuzzy matches:")
        for result in fuzzy_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 4: Search for recordings by Blink-182
        if blink182_results:
            blink182_mbid = blink182_results[0]['gid']
            print(f"\n4. Searching for recordings by Blink-182 (MBID: {blink182_mbid})...")
            cursor.execute("""
                SELECT r.name, r.gid
                FROM recording r
                JOIN artist_credit_name acn ON r.artist_credit = acn.artist_credit
                JOIN artist a ON acn.artist = a.id
                WHERE a.gid = %s
                LIMIT 5
            """, (blink182_mbid,))
            recordings = cursor.fetchall()
            print(f"   Found {len(recordings)} recordings:")
            for recording in recordings:
                print(f"     {recording['name']} (MBID: {recording['gid']})")
        
        cursor.close()
        connection.close()
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_blink182() 