"""Drop review_status columns and enums.

Revision ID: 007_drop_review_columns
Revises: 006_debug_columns
"""
from alembic import op

revision = "007_drop_review_columns"
down_revision = "006_debug_columns"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.drop_column("key_moments", "review_status")
    op.drop_column("technique_pages", "review_status")
    op.execute("DROP TYPE IF EXISTS review_status")
    op.execute("DROP TYPE IF EXISTS page_review_status")
    # Collapse 'reviewed' into 'published' for any existing rows
    op.execute(
        "UPDATE source_videos SET processing_status = 'published' "
        "WHERE processing_status = 'reviewed'"
    )


def downgrade() -> None:
    op.execute("CREATE TYPE review_status AS ENUM ('pending', 'approved', 'edited', 'rejected')")
    op.execute("CREATE TYPE page_review_status AS ENUM ('draft', 'reviewed', 'published')")
    op.add_column("key_moments", op.Column("review_status", op.Enum("pending", "approved", "edited", "rejected", name="review_status"), server_default="pending", nullable=False))
    op.add_column("technique_pages", op.Column("review_status", op.Enum("draft", "reviewed", "published", name="page_review_status"), server_default="draft", nullable=False))
