"""Add CheckoutLink

Revision ID: 3bd3e1bf77fb
Revises: c4cf133e597c
Create Date: 2024-10-16 14:11:33.667804

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "3bd3e1bf77fb"
down_revision = "c4cf133e597c"
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(
        "checkout_links",
        sa.Column("payment_processor", sa.String(), nullable=False),
        sa.Column("client_secret", sa.String(), nullable=False),
        sa.Column("success_url", sa.String(), nullable=True),
        sa.Column("product_price_id", sa.Uuid(), nullable=False),
        sa.Column(
            "user_metadata", postgresql.JSONB(astext_type=sa.Text()), nullable=False
        ),
        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.ForeignKeyConstraint(
            ["product_price_id"],
            ["product_prices.id"],
            name=op.f("checkout_links_product_price_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("checkout_links_pkey")),
    )
    op.create_index(
        op.f("ix_checkout_links_client_secret"),
        "checkout_links",
        ["client_secret"],
        unique=True,
    )
    op.create_index(
        op.f("ix_checkout_links_created_at"),
        "checkout_links",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_checkout_links_deleted_at"),
        "checkout_links",
        ["deleted_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_checkout_links_modified_at"),
        "checkout_links",
        ["modified_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_checkout_links_payment_processor"),
        "checkout_links",
        ["payment_processor"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_checkout_links_payment_processor"), table_name="checkout_links"
    )
    op.drop_index(op.f("ix_checkout_links_modified_at"), table_name="checkout_links")
    op.drop_index(op.f("ix_checkout_links_deleted_at"), table_name="checkout_links")
    op.drop_index(op.f("ix_checkout_links_created_at"), table_name="checkout_links")
    op.drop_index(op.f("ix_checkout_links_client_secret"), table_name="checkout_links")
    op.drop_table("checkout_links")
    # ### end Alembic commands ###
