"""video maintenance / validation columns

Revision ID: 0016_video_maintenance
Revises: 0015_scheduler_settings
Create Date: 2026-06-18

Adds the columns the maintenance/validation job needs to detect and retire unplayable
videos: videos.list?part=status fields (embeddable / privacy_status / upload_status) plus
the validation lifecycle (last_checked_at for rolling re-validation; unavailable_since +
unavailable_reason to flag a video as currently unplayable — hidden from the feed
immediately, hard-deleted after a grace period). Purely additive; all columns nullable.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0016_video_maintenance"
down_revision: Union[str, None] = "0015_scheduler_settings"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("videos", sa.Column("embeddable", sa.Boolean(), nullable=True))
    op.add_column("videos", sa.Column("privacy_status", sa.String(length=16), nullable=True))
    op.add_column("videos", sa.Column("upload_status", sa.String(length=16), nullable=True))
    op.add_column("videos", sa.Column("last_checked_at", sa.DateTime(timezone=True), nullable=True))
    op.add_column("videos", sa.Column("unavailable_since", sa.DateTime(timezone=True), nullable=True))
    op.add_column("videos", sa.Column("unavailable_reason", sa.String(length=24), nullable=True))
    op.create_index("ix_videos_last_checked_at", "videos", ["last_checked_at"])
    op.create_index("ix_videos_unavailable_since", "videos", ["unavailable_since"])


def downgrade() -> None:
    op.drop_index("ix_videos_unavailable_since", table_name="videos")
    op.drop_index("ix_videos_last_checked_at", table_name="videos")
    op.drop_column("videos", "unavailable_reason")
    op.drop_column("videos", "unavailable_since")
    op.drop_column("videos", "last_checked_at")
    op.drop_column("videos", "upload_status")
    op.drop_column("videos", "privacy_status")
    op.drop_column("videos", "embeddable")
