"""add_letzshop_vendor_fields_and_trial_tracking

Revision ID: 404b3e2d2865
Revises: l0a1b2c3d4e5
Create Date: 2025-12-27 09:49:44.715243

Adds:
- vendors.letzshop_vendor_id - Link to Letzshop marketplace profile
- vendors.letzshop_vendor_slug - Letzshop shop URL slug
- vendor_subscriptions.card_collected_at - Track when card was collected for trial
"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "404b3e2d2865"
down_revision: str | None = "l0a1b2c3d4e5"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # Add Letzshop vendor identity fields to vendors table
    op.add_column("vendors", sa.Column("letzshop_vendor_id", sa.String(length=100), nullable=True))
    op.add_column("vendors", sa.Column("letzshop_vendor_slug", sa.String(length=200), nullable=True))
    op.create_index(op.f("ix_vendors_letzshop_vendor_id"), "vendors", ["letzshop_vendor_id"], unique=True)
    op.create_index(op.f("ix_vendors_letzshop_vendor_slug"), "vendors", ["letzshop_vendor_slug"], unique=False)

    # Add card collection tracking to vendor_subscriptions
    op.add_column("vendor_subscriptions", sa.Column("card_collected_at", sa.DateTime(timezone=True), nullable=True))


def downgrade() -> None:
    # Remove card collection tracking from vendor_subscriptions
    op.drop_column("vendor_subscriptions", "card_collected_at")

    # Remove Letzshop vendor identity fields from vendors
    op.drop_index(op.f("ix_vendors_letzshop_vendor_slug"), table_name="vendors")
    op.drop_index(op.f("ix_vendors_letzshop_vendor_id"), table_name="vendors")
    op.drop_column("vendors", "letzshop_vendor_slug")
    op.drop_column("vendors", "letzshop_vendor_id")
