"""Add Dispute model

Revision ID: f8635d2a8d28
Revises: 9cc24f553f30
Create Date: 2025-12-03 11:24:42.166342

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "f8635d2a8d28"
down_revision = "9cc24f553f30"
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(
        "disputes",
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("modified_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("amount", sa.Integer(), nullable=False),
        sa.Column("tax_amount", sa.Integer(), nullable=False),
        sa.Column("currency", sa.String(length=3), nullable=False),
        sa.Column("payment_processor_id", sa.String(), nullable=True),
        sa.Column("dispute_alert_processor", sa.String(), nullable=True),
        sa.Column("dispute_alert_processor_id", sa.String(), nullable=True),
        sa.Column("order_id", sa.Uuid(), nullable=False),
        sa.Column("payment_id", sa.Uuid(), nullable=False),
        sa.Column("refund_id", sa.Uuid(), nullable=True),
        sa.ForeignKeyConstraint(
            ["order_id"], ["orders.id"], name=op.f("disputes_order_id_fkey")
        ),
        sa.ForeignKeyConstraint(
            ["payment_id"], ["payments.id"], name=op.f("disputes_payment_id_fkey")
        ),
        sa.ForeignKeyConstraint(
            ["refund_id"], ["refunds.id"], name=op.f("disputes_refund_id_fkey")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("disputes_pkey")),
    )
    op.create_index(
        op.f("ix_disputes_created_at"), "disputes", ["created_at"], unique=False
    )
    op.create_index(
        op.f("ix_disputes_deleted_at"), "disputes", ["deleted_at"], unique=False
    )
    op.create_index(
        op.f("ix_disputes_dispute_alert_processor_id"),
        "disputes",
        ["dispute_alert_processor_id"],
        unique=True,
    )
    op.create_index(
        op.f("ix_disputes_order_id"), "disputes", ["order_id"], unique=False
    )
    op.create_index(
        op.f("ix_disputes_payment_id"), "disputes", ["payment_id"], unique=False
    )
    op.create_index(
        op.f("ix_disputes_payment_processor_id"),
        "disputes",
        ["payment_processor_id"],
        unique=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_disputes_payment_processor_id"), table_name="disputes")
    op.drop_index(op.f("ix_disputes_payment_id"), table_name="disputes")
    op.drop_index(op.f("ix_disputes_order_id"), table_name="disputes")
    op.drop_index(op.f("ix_disputes_dispute_alert_processor_id"), table_name="disputes")
    op.drop_index(op.f("ix_disputes_deleted_at"), table_name="disputes")
    op.drop_index(op.f("ix_disputes_created_at"), table_name="disputes")
    op.drop_table("disputes")
    # ### end Alembic commands ###
