"""create_interchange_rates_table

Creates interchange_rates reference table for PRD-HWADM-002 (Story HWADM-210).

Revision ID: pricing002_interchange_rates
Revises: pricing001_core_tables
Create Date: 2026-04-29
"""
from alembic import op
import sqlalchemy as sa

revision = "pricing002_interchange_rates"
down_revision = "pricing001_core_tables"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "interchange_rates",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("card_network", sa.String(50), nullable=False),
        sa.Column("card_type", sa.String(50), nullable=False),
        sa.Column("transaction_type", sa.String(30), nullable=False),
        sa.Column("rate_percentage", sa.Float(), nullable=False),
        sa.Column("fixed_fee_cents", sa.Integer(), nullable=False, server_default="0"),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("effective_from", sa.DateTime(timezone=True), nullable=False),
        sa.Column("effective_to", sa.DateTime(timezone=True), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=False, server_default="true"),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index("ix_interchange_rates_is_active", "interchange_rates", ["is_active"])
    op.create_index("ix_interchange_rates_card_network", "interchange_rates", ["card_network"])


def downgrade() -> None:
    op.drop_table("interchange_rates")
