"""per-user blocked channels (YouTube search / feed / explore)

Revision ID: 0034_blocked_channels
Revises: 0033_channel_explore
Create Date: 2026-07-01

Adds the `blocked_channels` table: a per-user blocklist. Videos from a blocked channel are
never shown in that user's live YouTube search (and not ingested), and are hidden from their
feed / explore views. Per-user, so one user's block doesn't affect anyone else.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0034_blocked_channels"
down_revision: Union[str, None] = "0033_channel_explore"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "blocked_channels",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("channel_id", sa.String(length=32), nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(["channel_id"], ["channels.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("user_id", "channel_id", name="uq_user_blocked_channel"),
    )
    op.create_index("ix_blocked_channels_user_id", "blocked_channels", ["user_id"])
    op.create_index("ix_blocked_channels_channel_id", "blocked_channels", ["channel_id"])


def downgrade() -> None:
    op.drop_index("ix_blocked_channels_channel_id", table_name="blocked_channels")
    op.drop_index("ix_blocked_channels_user_id", table_name="blocked_channels")
    op.drop_table("blocked_channels")
