
import os
import psycopg2
from psycopg2.extras import RealDictCursor

def verify_bayern():
    try:
        db_url = os.environ.get('DATABASE_URL', 'postgresql://suggestbet:SuGGesT2026SecuRe@localhost:15432/boilerplate_db')
        conn = psycopg2.connect(db_url)
        cursor = conn.cursor(cursor_factory=RealDictCursor)
        
        print("\n🔍 BAYERN MUNICH 'CRISIS' CHECK")
        
        cursor.execute("""
            SELECT 
                m.mst_utc,
                ht.name as home, at.name as away,
                m.score_home, m.score_away
            FROM matches m
            JOIN teams ht ON m.home_team_id = ht.id
            JOIN teams at ON m.away_team_id = at.id
            WHERE (ht.name ILIKE '%Bayern Münih%' OR at.name ILIKE '%Bayern Münih%')
              AND (m.score_home >= 4 OR m.score_away >= 4)
            ORDER BY m.mst_utc DESC
            LIMIT 5
        """)
        
        results = cursor.fetchall()
        for r in results:
            print(f"{r['home']} {r['score_home']} - {r['score_away']} {r['away']}")
            
        conn.close()
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    verify_bayern()
