"""
Add text overlay fields to campaigns table
Run with: flask shell < migrations/add_campaign_text_overlay_fields.py
"""
from app.extensions import db
from app.models.campaign import Campaign

def upgrade():
    """Add text overlay fields to campaigns table"""
    # Check if columns exist
    inspector = db.inspect(db.engine)
    columns = [col['name'] for col in inspector.get_columns('campaigns')]

    if 'text_overlays' not in columns:
        print("Adding text_overlays column...")
        db.engine.execute(db.text("ALTER TABLE campaigns ADD COLUMN text_overlays JSONB"))

    if 'overlay_instructions' not in columns:
        print("Adding overlay_instructions column...")
        db.engine.execute(db.text("ALTER TABLE campaigns ADD COLUMN overlay_instructions JSONB"))

    if 'video_with_text_url' not in columns:
        print("Adding video_with_text_url column...")
        db.engine.execute(db.text("ALTER TABLE campaigns ADD COLUMN video_with_text_url TEXT"))

    print("✅ Text overlay fields added successfully!")

def downgrade():
    """Remove text overlay fields from campaigns table"""
    print("Removing text overlay fields...")
    db.engine.execute(db.text("ALTER TABLE campaigns DROP COLUMN IF EXISTS text_overlays"))
    db.engine.execute(db.text("ALTER TABLE campaigns DROP COLUMN IF EXISTS overlay_instructions"))
    db.engine.execute(db.text("ALTER TABLE campaigns DROP COLUMN IF EXISTS video_with_text_url"))
    print("✅ Text overlay fields removed!")

if __name__ == "__main__":
    upgrade()