"""add pattern tutorial fields

Revision ID: 004
Revises: 003
Create Date: 2025-05-10

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

revision: str = "004"
down_revision: str | None = "003"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # Tutorial content fields
    op.add_column("patterns", sa.Column("metaphor", sa.Text(), nullable=True))
    op.add_column("patterns", sa.Column("core_concept", sa.Text(), nullable=True))
    op.add_column("patterns", sa.Column("visualization", sa.Text(), nullable=True))
    op.add_column("patterns", sa.Column("code_template", sa.Text(), nullable=True))

    # Structured data fields (JSONB)
    op.add_column(
        "patterns",
        sa.Column(
            "recognition_signals",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )
    op.add_column(
        "patterns",
        sa.Column(
            "common_mistakes",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )
    op.add_column(
        "patterns",
        sa.Column(
            "variations",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )
    op.add_column(
        "patterns",
        sa.Column(
            "related_patterns",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )
    op.add_column(
        "patterns",
        sa.Column(
            "prerequisite_patterns",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )

    # Difficulty level (1-5)
    op.add_column("patterns", sa.Column("difficulty_level", sa.Integer(), nullable=True))


def downgrade() -> None:
    op.drop_column("patterns", "difficulty_level")
    op.drop_column("patterns", "prerequisite_patterns")
    op.drop_column("patterns", "related_patterns")
    op.drop_column("patterns", "variations")
    op.drop_column("patterns", "common_mistakes")
    op.drop_column("patterns", "recognition_signals")
    op.drop_column("patterns", "code_template")
    op.drop_column("patterns", "visualization")
    op.drop_column("patterns", "core_concept")
    op.drop_column("patterns", "metaphor")
