"""add show_in_legal to content_pages

Revision ID: ba2c0ce78396
Revises: m1b2c3d4e5f6
Create Date: 2025-12-28 20:00:24.263518

"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "ba2c0ce78396"
down_revision: str | None = "m1b2c3d4e5f6"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add show_in_legal column to content_pages table.

    This column controls whether a page appears in the bottom bar
    alongside the copyright notice (e.g., Privacy Policy, Terms of Service).
    """
    op.add_column(
        "content_pages",
        sa.Column("show_in_legal", sa.Boolean(), nullable=True, default=False)
    )

    # Set default value for existing rows (PostgreSQL uses true/false for boolean)
    op.execute("UPDATE content_pages SET show_in_legal = false WHERE show_in_legal IS NULL")

    # Set privacy and terms pages to show in legal by default
    op.execute("UPDATE content_pages SET show_in_legal = true WHERE slug IN ('privacy', 'terms')")


def downgrade() -> None:
    """Remove show_in_legal column from content_pages table."""
    op.drop_column("content_pages", "show_in_legal")
