"""create platform_payments table

Revision ID: 0025
Revises: 0024
Create Date: 2026-06-26
"""
from alembic import op
import sqlalchemy as sa

revision = "0025"
down_revision = "0024"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "platform_payments",
        sa.Column("id", sa.dialects.postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
        sa.Column("account_id", sa.dialects.postgresql.UUID(as_uuid=True), sa.ForeignKey("accounts.id", ondelete="CASCADE"), nullable=False),
        sa.Column("subscription_id", sa.dialects.postgresql.UUID(as_uuid=True), sa.ForeignKey("subscriptions.id", ondelete="SET NULL"), nullable=True),
        sa.Column("plan", sa.String(50), nullable=False),
        sa.Column("amount_cad", sa.Numeric(10, 2), nullable=False),
        sa.Column("method", sa.String(100), nullable=True),
        sa.Column("invoice_no", sa.String(100), nullable=True),
        sa.Column("source", sa.String(20), nullable=False, server_default="portal"),
        sa.Column("status", sa.String(20), nullable=False, server_default="paid"),
        sa.Column("payment_date", sa.Date, nullable=False),
        sa.Column("stripe_payment_intent_id", sa.String(255), nullable=True),
        sa.Column("notes", sa.Text, nullable=True),
        sa.Column("pdf_s3_key", sa.Text, nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("NOW()")),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("NOW()")),
    )
    op.create_index("ix_platform_payments_account_id", "platform_payments", ["account_id"])
    op.create_index("ix_platform_payments_payment_date", "platform_payments", ["payment_date"])
    op.create_index("ix_platform_payments_source", "platform_payments", ["source"])
    op.create_index("ix_platform_payments_plan", "platform_payments", ["plan"])
    op.create_index("ix_platform_payments_status", "platform_payments", ["status"])


def downgrade() -> None:
    op.drop_index("ix_platform_payments_status", table_name="platform_payments")
    op.drop_index("ix_platform_payments_plan", table_name="platform_payments")
    op.drop_index("ix_platform_payments_source", table_name="platform_payments")
    op.drop_index("ix_platform_payments_payment_date", table_name="platform_payments")
    op.drop_index("ix_platform_payments_account_id", table_name="platform_payments")
    op.drop_table("platform_payments")
