"""add trialing to billing status enum

Revision ID: 8014a3f5b255
Revises: bef4ae2f8131
Create Date: 2025-07-25 12:41:09.701470

"""

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

# revision identifiers, used by Alembic.
revision = "8014a3f5b255"
down_revision = "bef4ae2f8131"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "billing_event",
        "event_data",
        existing_type=postgresql.JSONB(astext_type=sa.Text()),
        type_=sa.JSON(),
        existing_nullable=True,
    )
    op.alter_column(
        "billing_event",
        "created_at",
        existing_type=postgresql.TIMESTAMP(timezone=True),
        type_=sa.DateTime(),
        existing_nullable=False,
    )
    op.alter_column(
        "billing_event",
        "modified_at",
        existing_type=postgresql.TIMESTAMP(timezone=True),
        type_=sa.DateTime(),
        existing_nullable=False,
    )
    op.alter_column(
        "organization_billing",
        "created_at",
        existing_type=postgresql.TIMESTAMP(timezone=True),
        type_=sa.DateTime(),
        existing_nullable=False,
    )
    op.alter_column(
        "organization_billing",
        "modified_at",
        existing_type=postgresql.TIMESTAMP(timezone=True),
        type_=sa.DateTime(),
        existing_nullable=False,
    )
    op.drop_index(op.f("idx_org_billing_stripe_customer"), table_name="organization_billing")
    op.drop_index(op.f("idx_org_billing_stripe_subscription"), table_name="organization_billing")
    op.drop_constraint(
        op.f("organization_billing_stripe_subscription_id_key"),
        "organization_billing",
        type_="unique",
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint(
        op.f("organization_billing_stripe_subscription_id_key"),
        "organization_billing",
        ["stripe_subscription_id"],
        postgresql_nulls_not_distinct=False,
    )
    op.create_index(
        op.f("idx_org_billing_stripe_subscription"),
        "organization_billing",
        ["stripe_subscription_id"],
        unique=False,
    )
    op.create_index(
        op.f("idx_org_billing_stripe_customer"),
        "organization_billing",
        ["stripe_customer_id"],
        unique=False,
    )
    op.alter_column(
        "organization_billing",
        "modified_at",
        existing_type=sa.DateTime(),
        type_=postgresql.TIMESTAMP(timezone=True),
        existing_nullable=False,
    )
    op.alter_column(
        "organization_billing",
        "created_at",
        existing_type=sa.DateTime(),
        type_=postgresql.TIMESTAMP(timezone=True),
        existing_nullable=False,
    )
    op.alter_column(
        "billing_event",
        "modified_at",
        existing_type=sa.DateTime(),
        type_=postgresql.TIMESTAMP(timezone=True),
        existing_nullable=False,
    )
    op.alter_column(
        "billing_event",
        "created_at",
        existing_type=sa.DateTime(),
        type_=postgresql.TIMESTAMP(timezone=True),
        existing_nullable=False,
    )
    op.alter_column(
        "billing_event",
        "event_data",
        existing_type=sa.JSON(),
        type_=postgresql.JSONB(astext_type=sa.Text()),
        existing_nullable=True,
    )
    # ### end Alembic commands ###
