"""
Create event_site_assets table and insert initial data
"""

import mysql.connector

db_config = {
    "host": "127.0.0.1",
    "user": "root",
    "password": "",
    "database": "event_ai"
}

try:
    conn = mysql.connector.connect(**db_config)
    cursor = conn.cursor()
    
    # Create table
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS event_site_assets (
            id INT AUTO_INCREMENT PRIMARY KEY,
            asset_type VARCHAR(50) NOT NULL UNIQUE,
            image_url TEXT NOT NULL,
            updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
        )
    """)
    print("✓ Table created")
    
    # Insert/update the three assets - UPDATE THESE WITH YOUR ACTUAL URLs
    assets = [
        ("header_image", "https://your-domain.com/header.jpg"),
        ("logo_image", "https://your-domain.com/logo.png"),
        ("footer_image", "https://your-domain.com/footer.jpg"),
    ]
    
    for asset_type, url in assets:
        cursor.execute("""
            INSERT INTO event_site_assets (asset_type, image_url)
            VALUES (%s, %s)
            ON DUPLICATE KEY UPDATE image_url = VALUES(image_url)
        """, (asset_type, url))
    
    conn.commit()
    print("✓ Assets inserted")
    
    # Verify
    cursor.execute("SELECT * FROM event_site_assets")
    rows = cursor.fetchall()
    print("\n=== event_site_assets ===")
    for row in rows:
        print(f"  {row}")
    
    cursor.close()
    conn.close()
    print("\n✓ Done!")

except Exception as e:
    print(f"✗ Error: {e}")
    import traceback
    traceback.print_exc()
