"""Add premium_requests.receipt_path + 'more_info' request status.

Completes Premium Management v2: an optional payment-receipt screenshot on a
request, and a 'more_info' review status for the "Request More Information"
action. On MySQL the ENUM column is widened; SQLite stores enums as VARCHAR
(created fresh via metadata), so only the new column is needed there.

Revision ID: b4d6f8a0c2e3
Revises: a3c5e7b9d1f0
Create Date: 2026-07-04

"""
from alembic import op
import sqlalchemy as sa


revision = "b4d6f8a0c2e3"
down_revision = "a3c5e7b9d1f0"
branch_labels = None
depends_on = None

_STATUS_NEW = "ENUM('pending','approved','rejected','more_info')"
_STATUS_OLD = "ENUM('pending','approved','rejected')"


def upgrade():
    with op.batch_alter_table("premium_requests", schema=None) as batch_op:
        batch_op.add_column(sa.Column("receipt_path", sa.String(length=255), nullable=True))
    if op.get_bind().dialect.name == "mysql":
        op.execute(f"ALTER TABLE premium_requests MODIFY COLUMN status {_STATUS_NEW} NOT NULL")


def downgrade():
    bind = op.get_bind()
    if bind.dialect.name == "mysql":
        op.execute("UPDATE premium_requests SET status='pending' WHERE status='more_info'")
        op.execute(f"ALTER TABLE premium_requests MODIFY COLUMN status {_STATUS_OLD} NOT NULL")
    with op.batch_alter_table("premium_requests", schema=None) as batch_op:
        batch_op.drop_column("receipt_path")
