"""loyalty 009 - replace category_id FK with category_ids JSON

Switches from single-category to multi-category support on transactions.
Not live yet so no data migration needed.

Revision ID: loyalty_009
Revises: loyalty_008
Create Date: 2026-04-19
"""
import sqlalchemy as sa

from alembic import op

revision = "loyalty_009"
down_revision = "loyalty_008"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.drop_column("loyalty_transactions", "category_id")
    op.add_column(
        "loyalty_transactions",
        sa.Column(
            "category_ids",
            sa.JSON(),
            nullable=True,
            comment="List of category IDs selected for this transaction",
        ),
    )


def downgrade() -> None:
    op.drop_column("loyalty_transactions", "category_ids")
    op.add_column(
        "loyalty_transactions",
        sa.Column(
            "category_id",
            sa.Integer(),
            sa.ForeignKey("store_transaction_categories.id", ondelete="SET NULL"),
            nullable=True,
        ),
    )
