#!/usr/bin/env python3
"""
Simple test to verify database connection method.
"""

import psycopg2

def test_connection_methods():
    """Test different connection methods."""
    print("🧪 Testing Database Connection Methods")
    print("=" * 50)
    
    # Test parameters
    test_configs = [
        {
            'host': 'localhost',
            'port': 5432,
            'database': 'musicbrainz_db',
            'user': 'musicbrainz',
            'password': 'musicbrainz',
            'description': 'localhost'
        },
        {
            'host': '172.18.0.2',
            'port': 5432,
            'database': 'musicbrainz_db',
            'user': 'musicbrainz',
            'password': 'musicbrainz',
            'description': 'Docker container IP'
        }
    ]
    
    for config in test_configs:
        print(f"\nTesting {config['description']}...")
        try:
            conn = psycopg2.connect(
                host=config['host'],
                port=config['port'],
                database=config['database'],
                user=config['user'],
                password=config['password'],
                connect_timeout=5
            )
            
            cursor = conn.cursor()
            cursor.execute("SELECT COUNT(*) FROM artist")
            count = cursor.fetchone()[0]
            print(f"✅ SUCCESS: {config['description']} - Found {count:,} artists")
            
            cursor.close()
            conn.close()
            return config['description']
            
        except Exception as e:
            print(f"❌ FAILED: {config['description']} - {e}")
            continue
    
    return None

if __name__ == "__main__":
    working_method = test_connection_methods()
    
    if working_method:
        print(f"\n🎉 Database connection working via: {working_method}")
    else:
        print(f"\n❌ No database connection method worked") 