"""Create content_reports table.

Revision ID: 003_content_reports
Revises: 002_technique_page_versions
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID

revision = "003_content_reports"
down_revision = "002_technique_page_versions"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "content_reports",
        sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.func.gen_random_uuid()),
        sa.Column("content_type", sa.String(50), nullable=False),
        sa.Column("content_id", UUID(as_uuid=True), nullable=True),
        sa.Column("content_title", sa.String(500), nullable=True),
        sa.Column("report_type", sa.Enum(
            "inaccurate", "missing_info", "wrong_attribution", "formatting", "other",
            name="report_type", create_constraint=True,
        ), nullable=False),
        sa.Column("description", sa.Text(), nullable=False),
        sa.Column("status", sa.Enum(
            "open", "acknowledged", "resolved", "dismissed",
            name="report_status", create_constraint=True,
        ), nullable=False, server_default="open"),
        sa.Column("admin_notes", sa.Text(), nullable=True),
        sa.Column("page_url", sa.String(1000), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.func.now(), nullable=False),
        sa.Column("resolved_at", sa.DateTime(), nullable=True),
    )

    op.create_index("ix_content_reports_status_created", "content_reports", ["status", "created_at"])
    op.create_index("ix_content_reports_content", "content_reports", ["content_type", "content_id"])


def downgrade() -> None:
    op.drop_index("ix_content_reports_content")
    op.drop_index("ix_content_reports_status_created")
    op.drop_table("content_reports")
    sa.Enum(name="report_status").drop(op.get_bind(), checkfirst=True)
    sa.Enum(name="report_type").drop(op.get_bind(), checkfirst=True)
