"""Add customer_seat pricing

Revision ID: 1ec8eb5dcb44
Revises: 3e8e0dcee197
Create Date: 2025-09-25 21:24:21.901013

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "1ec8eb5dcb44"
down_revision = "3e8e0dcee197"
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(
        "customer_seats",
        sa.Column("subscription_id", sa.Uuid(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("customer_id", sa.Uuid(), nullable=True),
        sa.Column("invitation_token", sa.String(), nullable=True),
        sa.Column("claimed_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("revoked_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("metadata", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
        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(
            ["customer_id"],
            ["customers.id"],
            name=op.f("customer_seats_customer_id_fkey"),
            ondelete="set null",
        ),
        sa.ForeignKeyConstraint(
            ["subscription_id"],
            ["subscriptions.id"],
            name=op.f("customer_seats_subscription_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("customer_seats_pkey")),
    )
    op.create_index(
        op.f("ix_customer_seats_created_at"),
        "customer_seats",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_seats_customer_id"),
        "customer_seats",
        ["customer_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_seats_deleted_at"),
        "customer_seats",
        ["deleted_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_seats_invitation_token"),
        "customer_seats",
        ["invitation_token"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_seats_subscription_id"),
        "customer_seats",
        ["subscription_id"],
        unique=False,
    )
    op.add_column(
        "product_prices", sa.Column("price_per_seat", sa.Integer(), nullable=True)
    )
    op.add_column("subscriptions", sa.Column("seats", sa.Integer(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("subscriptions", "seats")
    op.drop_column("product_prices", "price_per_seat")
    op.drop_index(
        op.f("ix_customer_seats_subscription_id"), table_name="customer_seats"
    )
    op.drop_index(
        op.f("ix_customer_seats_invitation_token"), table_name="customer_seats"
    )
    op.drop_index(op.f("ix_customer_seats_deleted_at"), table_name="customer_seats")
    op.drop_index(op.f("ix_customer_seats_customer_id"), table_name="customer_seats")
    op.drop_index(op.f("ix_customer_seats_created_at"), table_name="customer_seats")
    op.drop_table("customer_seats")
    # ### end Alembic commands ###
