"""Ensure content_pages table with all columns

Revision ID: 72aa309d4007
Revises: fef1d20ce8b4
Create Date: 2025-11-22 15:16:13.213613

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "content_pages",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=True),
        sa.Column("slug", sa.String(length=100), nullable=False),
        sa.Column("title", sa.String(length=200), nullable=False),
        sa.Column("content", sa.Text(), nullable=False),
        sa.Column("content_format", sa.String(length=20), nullable=True),
        sa.Column("meta_description", sa.String(length=300), nullable=True),
        sa.Column("meta_keywords", sa.String(length=300), nullable=True),
        sa.Column("is_published", sa.Boolean(), nullable=False),
        sa.Column("published_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("display_order", sa.Integer(), nullable=True),
        sa.Column("show_in_footer", sa.Boolean(), nullable=True),
        sa.Column("show_in_header", sa.Boolean(), nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("created_by", sa.Integer(), nullable=True),
        sa.Column("updated_by", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["created_by"], ["users.id"], ondelete="SET NULL"),
        sa.ForeignKeyConstraint(["updated_by"], ["users.id"], ondelete="SET NULL"),
        sa.ForeignKeyConstraint(["vendor_id"], ["vendors.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("vendor_id", "slug", name="uq_vendor_slug"),
    )
    op.create_index(
        "idx_slug_published", "content_pages", ["slug", "is_published"], unique=False
    )
    op.create_index(
        "idx_vendor_published",
        "content_pages",
        ["vendor_id", "is_published"],
        unique=False,
    )
    op.create_index(op.f("ix_content_pages_id"), "content_pages", ["id"], unique=False)
    op.create_index(
        op.f("ix_content_pages_slug"), "content_pages", ["slug"], unique=False
    )
    op.create_index(
        op.f("ix_content_pages_vendor_id"), "content_pages", ["vendor_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_content_pages_vendor_id"), table_name="content_pages")
    op.drop_index(op.f("ix_content_pages_slug"), table_name="content_pages")
    op.drop_index(op.f("ix_content_pages_id"), table_name="content_pages")
    op.drop_index("idx_vendor_published", table_name="content_pages")
    op.drop_index("idx_slug_published", table_name="content_pages")
    op.drop_table("content_pages")
    # ### end Alembic commands ###
