"""Add ProcessorTransaction

Revision ID: 33e67212795d
Revises: 71dd42ca673e
Create Date: 2025-07-10 17:30:02.495387

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "33e67212795d"
down_revision = "71dd42ca673e"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "processor_transactions",
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column("timestamp", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("processor", sa.String(), nullable=False),
        sa.Column("processor_id", sa.String(), nullable=False),
        sa.Column("type", sa.String(), nullable=False),
        sa.Column("currency", sa.String(length=3), nullable=False),
        sa.Column("amount", sa.BigInteger(), nullable=False),
        sa.Column("fee", sa.BigInteger(), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("raw", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("processor_transactions_pkey")),
    )
    op.create_index(
        op.f("ix_processor_transactions_processor"),
        "processor_transactions",
        ["processor"],
        unique=False,
    )
    op.create_index(
        op.f("ix_processor_transactions_processor_id"),
        "processor_transactions",
        ["processor_id"],
        unique=True,
    )
    op.create_index(
        op.f("ix_processor_transactions_timestamp"),
        "processor_transactions",
        ["timestamp"],
        unique=False,
    )
    op.create_index(
        op.f("ix_processor_transactions_type"),
        "processor_transactions",
        ["type"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_processor_transactions_type"), table_name="processor_transactions"
    )
    op.drop_index(
        op.f("ix_processor_transactions_timestamp"), table_name="processor_transactions"
    )
    op.drop_index(
        op.f("ix_processor_transactions_processor_id"),
        table_name="processor_transactions",
    )
    op.drop_index(
        op.f("ix_processor_transactions_processor"), table_name="processor_transactions"
    )
    op.drop_table("processor_transactions")
    # ### end Alembic commands ###
