"""Add generated_shorts table with format_preset and short_status enums.

Revision ID: 025_add_generated_shorts
Revises: 024_add_posts_and_attachments
"""

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID

from alembic import op

revision = "025_add_generated_shorts"
down_revision = "024_add_posts_and_attachments"
branch_labels = None
depends_on = None

format_preset_enum = sa.Enum("vertical", "square", "horizontal", name="format_preset")
short_status_enum = sa.Enum("pending", "processing", "complete", "failed", name="short_status")


def upgrade() -> None:
    format_preset_enum.create(op.get_bind(), checkfirst=True)
    short_status_enum.create(op.get_bind(), checkfirst=True)

    op.create_table(
        "generated_shorts",
        sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.func.gen_random_uuid()),
        sa.Column("highlight_candidate_id", UUID(as_uuid=True), sa.ForeignKey("highlight_candidates.id", ondelete="CASCADE"), nullable=False, index=True),
        sa.Column("format_preset", format_preset_enum, nullable=False),
        sa.Column("minio_object_key", sa.String(1000), nullable=True),
        sa.Column("duration_secs", sa.Float, nullable=True),
        sa.Column("width", sa.Integer, nullable=False),
        sa.Column("height", sa.Integer, nullable=False),
        sa.Column("file_size_bytes", sa.BigInteger, nullable=True),
        sa.Column("status", short_status_enum, nullable=False, server_default="pending"),
        sa.Column("error_message", sa.Text, nullable=True),
        sa.Column("created_at", sa.DateTime, nullable=False, server_default=sa.func.now()),
        sa.Column("updated_at", sa.DateTime, nullable=False, server_default=sa.func.now()),
    )


def downgrade() -> None:
    op.drop_table("generated_shorts")
    short_status_enum.drop(op.get_bind(), checkfirst=True)
    format_preset_enum.drop(op.get_bind(), checkfirst=True)
