"""promo code point refund tracking

Revision ID: 053_promo_code_point_refunded
Revises: 052_promo_code_issuer
Create Date: 2026-06-20
"""

import sqlalchemy as sa
from alembic import op


revision = "053_promo_code_point_refunded"
down_revision = "052_promo_code_issuer"
branch_labels = None
depends_on = None


def _columns(bind, table_name: str) -> set[str]:
    return {column["name"] for column in sa.inspect(bind).get_columns(table_name)}


def upgrade() -> None:
    bind = op.get_bind()
    columns = _columns(bind, "promo_codes")
    if "point_refunded" not in columns:
        op.add_column("promo_codes", sa.Column("point_refunded", sa.Integer(), nullable=False, server_default="0"))


def downgrade() -> None:
    bind = op.get_bind()
    columns = _columns(bind, "promo_codes")
    if "point_refunded" in columns:
        op.drop_column("promo_codes", "point_refunded")
