"""Initial migration - all tables

Revision ID: 4951b2e50581
Revises:
Create Date: 2025-10-27 22:28:33.137564

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "marketplace_products",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("marketplace_product_id", sa.String(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("link", sa.String(), nullable=True),
        sa.Column("image_link", sa.String(), nullable=True),
        sa.Column("availability", sa.String(), nullable=True),
        sa.Column("price", sa.String(), nullable=True),
        sa.Column("brand", sa.String(), nullable=True),
        sa.Column("gtin", sa.String(), nullable=True),
        sa.Column("mpn", sa.String(), nullable=True),
        sa.Column("condition", sa.String(), nullable=True),
        sa.Column("adult", sa.String(), nullable=True),
        sa.Column("multipack", sa.Integer(), nullable=True),
        sa.Column("is_bundle", sa.String(), nullable=True),
        sa.Column("age_group", sa.String(), nullable=True),
        sa.Column("color", sa.String(), nullable=True),
        sa.Column("gender", sa.String(), nullable=True),
        sa.Column("material", sa.String(), nullable=True),
        sa.Column("pattern", sa.String(), nullable=True),
        sa.Column("size", sa.String(), nullable=True),
        sa.Column("size_type", sa.String(), nullable=True),
        sa.Column("size_system", sa.String(), nullable=True),
        sa.Column("item_group_id", sa.String(), nullable=True),
        sa.Column("google_product_category", sa.String(), nullable=True),
        sa.Column("product_type", sa.String(), nullable=True),
        sa.Column("custom_label_0", sa.String(), nullable=True),
        sa.Column("custom_label_1", sa.String(), nullable=True),
        sa.Column("custom_label_2", sa.String(), nullable=True),
        sa.Column("custom_label_3", sa.String(), nullable=True),
        sa.Column("custom_label_4", sa.String(), nullable=True),
        sa.Column("additional_image_link", sa.String(), nullable=True),
        sa.Column("sale_price", sa.String(), nullable=True),
        sa.Column("unit_pricing_measure", sa.String(), nullable=True),
        sa.Column("unit_pricing_base_measure", sa.String(), nullable=True),
        sa.Column("identifier_exists", sa.String(), nullable=True),
        sa.Column("shipping", sa.String(), nullable=True),
        sa.Column("currency", sa.String(), nullable=True),
        sa.Column("marketplace", sa.String(), nullable=True),
        sa.Column("vendor_name", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        "idx_marketplace_brand",
        "marketplace_products",
        ["marketplace", "brand"],
        unique=False,
    )
    op.create_index(
        "idx_marketplace_vendor",
        "marketplace_products",
        ["marketplace", "vendor_name"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_availability"),
        "marketplace_products",
        ["availability"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_brand"),
        "marketplace_products",
        ["brand"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_google_product_category"),
        "marketplace_products",
        ["google_product_category"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_gtin"),
        "marketplace_products",
        ["gtin"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_id"), "marketplace_products", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_marketplace_products_marketplace"),
        "marketplace_products",
        ["marketplace"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_products_marketplace_product_id"),
        "marketplace_products",
        ["marketplace_product_id"],
        unique=True,
    )
    op.create_index(
        op.f("ix_marketplace_products_vendor_name"),
        "marketplace_products",
        ["vendor_name"],
        unique=False,
    )
    op.create_table(
        "users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(), nullable=False),
        sa.Column("username", sa.String(), nullable=False),
        sa.Column("first_name", sa.String(), nullable=True),
        sa.Column("last_name", sa.String(), nullable=True),
        sa.Column("hashed_password", sa.String(), nullable=False),
        sa.Column("role", sa.String(), nullable=False),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("last_login", sa.DateTime(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
    op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
    op.create_index(op.f("ix_users_username"), "users", ["username"], unique=True)
    op.create_table(
        "admin_audit_logs",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("admin_user_id", sa.Integer(), nullable=False),
        sa.Column("action", sa.String(length=100), nullable=False),
        sa.Column("target_type", sa.String(length=50), nullable=False),
        sa.Column("target_id", sa.String(length=100), nullable=False),
        sa.Column("details", sa.JSON(), nullable=True),
        sa.Column("ip_address", sa.String(length=45), nullable=True),
        sa.Column("user_agent", sa.Text(), nullable=True),
        sa.Column("request_id", sa.String(length=100), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["admin_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_admin_audit_logs_action"), "admin_audit_logs", ["action"], unique=False
    )
    op.create_index(
        op.f("ix_admin_audit_logs_admin_user_id"),
        "admin_audit_logs",
        ["admin_user_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_audit_logs_id"), "admin_audit_logs", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_admin_audit_logs_target_id"),
        "admin_audit_logs",
        ["target_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_audit_logs_target_type"),
        "admin_audit_logs",
        ["target_type"],
        unique=False,
    )
    op.create_table(
        "admin_notifications",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("type", sa.String(length=50), nullable=False),
        sa.Column("priority", sa.String(length=20), nullable=True),
        sa.Column("title", sa.String(length=200), nullable=False),
        sa.Column("message", sa.Text(), nullable=False),
        sa.Column("is_read", sa.Boolean(), nullable=True),
        sa.Column("read_at", sa.DateTime(), nullable=True),
        sa.Column("read_by_user_id", sa.Integer(), nullable=True),
        sa.Column("action_required", sa.Boolean(), nullable=True),
        sa.Column("action_url", sa.String(length=500), nullable=True),
        sa.Column("notification_metadata", sa.JSON(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["read_by_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_admin_notifications_action_required"),
        "admin_notifications",
        ["action_required"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_notifications_id"), "admin_notifications", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_admin_notifications_is_read"),
        "admin_notifications",
        ["is_read"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_notifications_priority"),
        "admin_notifications",
        ["priority"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_notifications_type"),
        "admin_notifications",
        ["type"],
        unique=False,
    )
    op.create_table(
        "admin_sessions",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("admin_user_id", sa.Integer(), nullable=False),
        sa.Column("session_token", sa.String(length=255), nullable=False),
        sa.Column("ip_address", sa.String(length=45), nullable=False),
        sa.Column("user_agent", sa.Text(), nullable=True),
        sa.Column("login_at", sa.DateTime(), nullable=False),
        sa.Column("last_activity_at", sa.DateTime(), nullable=False),
        sa.Column("logout_at", sa.DateTime(), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("logout_reason", sa.String(length=50), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["admin_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_admin_sessions_admin_user_id"),
        "admin_sessions",
        ["admin_user_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_sessions_id"), "admin_sessions", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_admin_sessions_is_active"),
        "admin_sessions",
        ["is_active"],
        unique=False,
    )
    op.create_index(
        op.f("ix_admin_sessions_login_at"), "admin_sessions", ["login_at"], unique=False
    )
    op.create_index(
        op.f("ix_admin_sessions_session_token"),
        "admin_sessions",
        ["session_token"],
        unique=True,
    )
    op.create_table(
        "admin_settings",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("key", sa.String(length=100), nullable=False),
        sa.Column("value", sa.Text(), nullable=False),
        sa.Column("value_type", sa.String(length=20), nullable=True),
        sa.Column("category", sa.String(length=50), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("is_encrypted", sa.Boolean(), nullable=True),
        sa.Column("is_public", sa.Boolean(), nullable=True),
        sa.Column("last_modified_by_user_id", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["last_modified_by_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_admin_settings_category"), "admin_settings", ["category"], unique=False
    )
    op.create_index(
        op.f("ix_admin_settings_id"), "admin_settings", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_admin_settings_key"), "admin_settings", ["key"], unique=True
    )
    op.create_table(
        "platform_alerts",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("alert_type", sa.String(length=50), nullable=False),
        sa.Column("severity", sa.String(length=20), nullable=False),
        sa.Column("title", sa.String(length=200), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("affected_vendors", sa.JSON(), nullable=True),
        sa.Column("affected_systems", sa.JSON(), nullable=True),
        sa.Column("is_resolved", sa.Boolean(), nullable=True),
        sa.Column("resolved_at", sa.DateTime(), nullable=True),
        sa.Column("resolved_by_user_id", sa.Integer(), nullable=True),
        sa.Column("resolution_notes", sa.Text(), nullable=True),
        sa.Column("auto_generated", sa.Boolean(), nullable=True),
        sa.Column("occurrence_count", sa.Integer(), nullable=True),
        sa.Column("first_occurred_at", sa.DateTime(), nullable=False),
        sa.Column("last_occurred_at", sa.DateTime(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["resolved_by_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_platform_alerts_alert_type"),
        "platform_alerts",
        ["alert_type"],
        unique=False,
    )
    op.create_index(
        op.f("ix_platform_alerts_id"), "platform_alerts", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_platform_alerts_is_resolved"),
        "platform_alerts",
        ["is_resolved"],
        unique=False,
    )
    op.create_index(
        op.f("ix_platform_alerts_severity"),
        "platform_alerts",
        ["severity"],
        unique=False,
    )
    op.create_table(
        "vendors",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_code", sa.String(), nullable=False),
        sa.Column("subdomain", sa.String(length=100), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("owner_user_id", sa.Integer(), nullable=False),
        sa.Column("contact_email", sa.String(), nullable=True),
        sa.Column("contact_phone", sa.String(), nullable=True),
        sa.Column("website", sa.String(), nullable=True),
        sa.Column("letzshop_csv_url_fr", sa.String(), nullable=True),
        sa.Column("letzshop_csv_url_en", sa.String(), nullable=True),
        sa.Column("letzshop_csv_url_de", sa.String(), nullable=True),
        sa.Column("business_address", sa.Text(), nullable=True),
        sa.Column("tax_number", sa.String(), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("is_verified", sa.Boolean(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["owner_user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_vendors_id"), "vendors", ["id"], unique=False)
    op.create_index(op.f("ix_vendors_subdomain"), "vendors", ["subdomain"], unique=True)
    op.create_index(
        op.f("ix_vendors_vendor_code"), "vendors", ["vendor_code"], unique=True
    )
    op.create_table(
        "customers",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(length=255), nullable=False),
        sa.Column("hashed_password", sa.String(length=255), nullable=False),
        sa.Column("first_name", sa.String(length=100), nullable=True),
        sa.Column("last_name", sa.String(length=100), nullable=True),
        sa.Column("phone", sa.String(length=50), nullable=True),
        sa.Column("customer_number", sa.String(length=100), nullable=False),
        sa.Column("preferences", sa.JSON(), nullable=True),
        sa.Column("marketing_consent", sa.Boolean(), nullable=True),
        sa.Column("last_order_date", sa.DateTime(), nullable=True),
        sa.Column("total_orders", sa.Integer(), nullable=True),
        sa.Column("total_spent", sa.Numeric(precision=10, scale=2), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_customers_customer_number"),
        "customers",
        ["customer_number"],
        unique=False,
    )
    op.create_index(op.f("ix_customers_email"), "customers", ["email"], unique=False)
    op.create_index(op.f("ix_customers_id"), "customers", ["id"], unique=False)
    op.create_table(
        "marketplace_import_jobs",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("marketplace", sa.String(), nullable=False),
        sa.Column("source_url", sa.String(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("imported_count", sa.Integer(), nullable=True),
        sa.Column("updated_count", sa.Integer(), nullable=True),
        sa.Column("error_count", sa.Integer(), nullable=True),
        sa.Column("total_processed", sa.Integer(), nullable=True),
        sa.Column("error_message", sa.Text(), nullable=True),
        sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        "idx_import_user_marketplace",
        "marketplace_import_jobs",
        ["user_id", "marketplace"],
        unique=False,
    )
    op.create_index(
        "idx_import_vendor_created",
        "marketplace_import_jobs",
        ["vendor_id", "created_at"],
        unique=False,
    )
    op.create_index(
        "idx_import_vendor_status",
        "marketplace_import_jobs",
        ["vendor_id", "status"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_import_jobs_id"),
        "marketplace_import_jobs",
        ["id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_import_jobs_marketplace"),
        "marketplace_import_jobs",
        ["marketplace"],
        unique=False,
    )
    op.create_index(
        op.f("ix_marketplace_import_jobs_vendor_id"),
        "marketplace_import_jobs",
        ["vendor_id"],
        unique=False,
    )
    op.create_table(
        "products",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("marketplace_product_id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.String(), nullable=True),
        sa.Column("price", sa.Float(), nullable=True),
        sa.Column("sale_price", sa.Float(), nullable=True),
        sa.Column("currency", sa.String(), nullable=True),
        sa.Column("availability", sa.String(), nullable=True),
        sa.Column("condition", sa.String(), nullable=True),
        sa.Column("is_featured", sa.Boolean(), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("display_order", sa.Integer(), nullable=True),
        sa.Column("min_quantity", sa.Integer(), nullable=True),
        sa.Column("max_quantity", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["marketplace_product_id"],
            ["marketplace_products.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("vendor_id", "marketplace_product_id", name="uq_product"),
    )
    op.create_index(
        "idx_product_active", "products", ["vendor_id", "is_active"], unique=False
    )
    op.create_index(
        "idx_product_featured", "products", ["vendor_id", "is_featured"], unique=False
    )
    op.create_index(op.f("ix_products_id"), "products", ["id"], unique=False)
    op.create_table(
        "roles",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("permissions", sa.JSON(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_roles_id"), "roles", ["id"], unique=False)
    op.create_table(
        "vendor_domains",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("domain", sa.String(length=255), nullable=False),
        sa.Column("is_primary", sa.Boolean(), nullable=False),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("ssl_status", sa.String(length=50), nullable=True),
        sa.Column("ssl_verified_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("verification_token", sa.String(length=100), nullable=True),
        sa.Column("is_verified", sa.Boolean(), nullable=False),
        sa.Column("verified_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(["vendor_id"], ["vendors.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("vendor_id", "domain", name="uq_vendor_domain"),
        sa.UniqueConstraint("verification_token"),
    )
    op.create_index(
        "idx_domain_active", "vendor_domains", ["domain", "is_active"], unique=False
    )
    op.create_index(
        "idx_vendor_primary",
        "vendor_domains",
        ["vendor_id", "is_primary"],
        unique=False,
    )
    op.create_index(
        op.f("ix_vendor_domains_domain"), "vendor_domains", ["domain"], unique=True
    )
    op.create_index(
        op.f("ix_vendor_domains_id"), "vendor_domains", ["id"], unique=False
    )
    op.create_table(
        "vendor_themes",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("theme_name", sa.String(length=100), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("colors", sa.JSON(), nullable=True),
        sa.Column("font_family_heading", sa.String(length=100), nullable=True),
        sa.Column("font_family_body", sa.String(length=100), nullable=True),
        sa.Column("logo_url", sa.String(length=500), nullable=True),
        sa.Column("logo_dark_url", sa.String(length=500), nullable=True),
        sa.Column("favicon_url", sa.String(length=500), nullable=True),
        sa.Column("banner_url", sa.String(length=500), nullable=True),
        sa.Column("layout_style", sa.String(length=50), nullable=True),
        sa.Column("header_style", sa.String(length=50), nullable=True),
        sa.Column("product_card_style", sa.String(length=50), nullable=True),
        sa.Column("custom_css", sa.Text(), nullable=True),
        sa.Column("social_links", sa.JSON(), nullable=True),
        sa.Column("meta_title_template", sa.String(length=200), nullable=True),
        sa.Column("meta_description", sa.Text(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(["vendor_id"], ["vendors.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("vendor_id"),
    )
    op.create_index(op.f("ix_vendor_themes_id"), "vendor_themes", ["id"], unique=False)
    op.create_table(
        "customer_addresses",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("customer_id", sa.Integer(), nullable=False),
        sa.Column("address_type", sa.String(length=50), nullable=False),
        sa.Column("first_name", sa.String(length=100), nullable=False),
        sa.Column("last_name", sa.String(length=100), nullable=False),
        sa.Column("company", sa.String(length=200), nullable=True),
        sa.Column("address_line_1", sa.String(length=255), nullable=False),
        sa.Column("address_line_2", sa.String(length=255), nullable=True),
        sa.Column("city", sa.String(length=100), nullable=False),
        sa.Column("postal_code", sa.String(length=20), nullable=False),
        sa.Column("country", sa.String(length=100), nullable=False),
        sa.Column("is_default", sa.Boolean(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["customer_id"],
            ["customers.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_customer_addresses_id"), "customer_addresses", ["id"], unique=False
    )
    op.create_table(
        "inventory",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("location", sa.String(), nullable=False),
        sa.Column("quantity", sa.Integer(), nullable=False),
        sa.Column("reserved_quantity", sa.Integer(), nullable=True),
        sa.Column("gtin", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["products.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "product_id", "location", name="uq_inventory_product_location"
        ),
    )
    op.create_index(
        "idx_inventory_product_location",
        "inventory",
        ["product_id", "location"],
        unique=False,
    )
    op.create_index(
        "idx_inventory_vendor_product",
        "inventory",
        ["vendor_id", "product_id"],
        unique=False,
    )
    op.create_index(op.f("ix_inventory_gtin"), "inventory", ["gtin"], unique=False)
    op.create_index(op.f("ix_inventory_id"), "inventory", ["id"], unique=False)
    op.create_index(
        op.f("ix_inventory_location"), "inventory", ["location"], unique=False
    )
    op.create_index(
        op.f("ix_inventory_product_id"), "inventory", ["product_id"], unique=False
    )
    op.create_index(
        op.f("ix_inventory_vendor_id"), "inventory", ["vendor_id"], unique=False
    )
    op.create_table(
        "vendor_users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("role_id", sa.Integer(), nullable=False),
        sa.Column("invited_by", sa.Integer(), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["invited_by"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["role_id"],
            ["roles.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_vendor_users_id"), "vendor_users", ["id"], unique=False)
    op.create_table(
        "orders",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("vendor_id", sa.Integer(), nullable=False),
        sa.Column("customer_id", sa.Integer(), nullable=False),
        sa.Column("order_number", sa.String(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("subtotal", sa.Float(), nullable=False),
        sa.Column("tax_amount", sa.Float(), nullable=True),
        sa.Column("shipping_amount", sa.Float(), nullable=True),
        sa.Column("discount_amount", sa.Float(), nullable=True),
        sa.Column("total_amount", sa.Float(), nullable=False),
        sa.Column("currency", sa.String(), nullable=True),
        sa.Column("shipping_address_id", sa.Integer(), nullable=False),
        sa.Column("billing_address_id", sa.Integer(), nullable=False),
        sa.Column("shipping_method", sa.String(), nullable=True),
        sa.Column("tracking_number", sa.String(), nullable=True),
        sa.Column("customer_notes", sa.Text(), nullable=True),
        sa.Column("internal_notes", sa.Text(), nullable=True),
        sa.Column("paid_at", sa.DateTime(), nullable=True),
        sa.Column("shipped_at", sa.DateTime(), nullable=True),
        sa.Column("delivered_at", sa.DateTime(), nullable=True),
        sa.Column("cancelled_at", sa.DateTime(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["billing_address_id"],
            ["customer_addresses.id"],
        ),
        sa.ForeignKeyConstraint(
            ["customer_id"],
            ["customers.id"],
        ),
        sa.ForeignKeyConstraint(
            ["shipping_address_id"],
            ["customer_addresses.id"],
        ),
        sa.ForeignKeyConstraint(
            ["vendor_id"],
            ["vendors.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_orders_customer_id"), "orders", ["customer_id"], unique=False
    )
    op.create_index(op.f("ix_orders_id"), "orders", ["id"], unique=False)
    op.create_index(
        op.f("ix_orders_order_number"), "orders", ["order_number"], unique=True
    )
    op.create_index(op.f("ix_orders_status"), "orders", ["status"], unique=False)
    op.create_index(op.f("ix_orders_vendor_id"), "orders", ["vendor_id"], unique=False)
    op.create_table(
        "order_items",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("order_id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("product_name", sa.String(), nullable=False),
        sa.Column("product_sku", sa.String(), nullable=True),
        sa.Column("quantity", sa.Integer(), nullable=False),
        sa.Column("unit_price", sa.Float(), nullable=False),
        sa.Column("total_price", sa.Float(), nullable=False),
        sa.Column("inventory_reserved", sa.Boolean(), nullable=True),
        sa.Column("inventory_fulfilled", sa.Boolean(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["order_id"],
            ["orders.id"],
        ),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["products.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_order_items_id"), "order_items", ["id"], unique=False)
    op.create_index(
        op.f("ix_order_items_order_id"), "order_items", ["order_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_order_items_order_id"), table_name="order_items")
    op.drop_index(op.f("ix_order_items_id"), table_name="order_items")
    op.drop_table("order_items")
    op.drop_index(op.f("ix_orders_vendor_id"), table_name="orders")
    op.drop_index(op.f("ix_orders_status"), table_name="orders")
    op.drop_index(op.f("ix_orders_order_number"), table_name="orders")
    op.drop_index(op.f("ix_orders_id"), table_name="orders")
    op.drop_index(op.f("ix_orders_customer_id"), table_name="orders")
    op.drop_table("orders")
    op.drop_index(op.f("ix_vendor_users_id"), table_name="vendor_users")
    op.drop_table("vendor_users")
    op.drop_index(op.f("ix_inventory_vendor_id"), table_name="inventory")
    op.drop_index(op.f("ix_inventory_product_id"), table_name="inventory")
    op.drop_index(op.f("ix_inventory_location"), table_name="inventory")
    op.drop_index(op.f("ix_inventory_id"), table_name="inventory")
    op.drop_index(op.f("ix_inventory_gtin"), table_name="inventory")
    op.drop_index("idx_inventory_vendor_product", table_name="inventory")
    op.drop_index("idx_inventory_product_location", table_name="inventory")
    op.drop_table("inventory")
    op.drop_index(op.f("ix_customer_addresses_id"), table_name="customer_addresses")
    op.drop_table("customer_addresses")
    op.drop_index(op.f("ix_vendor_themes_id"), table_name="vendor_themes")
    op.drop_table("vendor_themes")
    op.drop_index(op.f("ix_vendor_domains_id"), table_name="vendor_domains")
    op.drop_index(op.f("ix_vendor_domains_domain"), table_name="vendor_domains")
    op.drop_index("idx_vendor_primary", table_name="vendor_domains")
    op.drop_index("idx_domain_active", table_name="vendor_domains")
    op.drop_table("vendor_domains")
    op.drop_index(op.f("ix_roles_id"), table_name="roles")
    op.drop_table("roles")
    op.drop_index(op.f("ix_products_id"), table_name="products")
    op.drop_index("idx_product_featured", table_name="products")
    op.drop_index("idx_product_active", table_name="products")
    op.drop_table("products")
    op.drop_index(
        op.f("ix_marketplace_import_jobs_vendor_id"),
        table_name="marketplace_import_jobs",
    )
    op.drop_index(
        op.f("ix_marketplace_import_jobs_marketplace"),
        table_name="marketplace_import_jobs",
    )
    op.drop_index(
        op.f("ix_marketplace_import_jobs_id"), table_name="marketplace_import_jobs"
    )
    op.drop_index("idx_import_vendor_status", table_name="marketplace_import_jobs")
    op.drop_index("idx_import_vendor_created", table_name="marketplace_import_jobs")
    op.drop_index("idx_import_user_marketplace", table_name="marketplace_import_jobs")
    op.drop_table("marketplace_import_jobs")
    op.drop_index(op.f("ix_customers_id"), table_name="customers")
    op.drop_index(op.f("ix_customers_email"), table_name="customers")
    op.drop_index(op.f("ix_customers_customer_number"), table_name="customers")
    op.drop_table("customers")
    op.drop_index(op.f("ix_vendors_vendor_code"), table_name="vendors")
    op.drop_index(op.f("ix_vendors_subdomain"), table_name="vendors")
    op.drop_index(op.f("ix_vendors_id"), table_name="vendors")
    op.drop_table("vendors")
    op.drop_index(op.f("ix_platform_alerts_severity"), table_name="platform_alerts")
    op.drop_index(op.f("ix_platform_alerts_is_resolved"), table_name="platform_alerts")
    op.drop_index(op.f("ix_platform_alerts_id"), table_name="platform_alerts")
    op.drop_index(op.f("ix_platform_alerts_alert_type"), table_name="platform_alerts")
    op.drop_table("platform_alerts")
    op.drop_index(op.f("ix_admin_settings_key"), table_name="admin_settings")
    op.drop_index(op.f("ix_admin_settings_id"), table_name="admin_settings")
    op.drop_index(op.f("ix_admin_settings_category"), table_name="admin_settings")
    op.drop_table("admin_settings")
    op.drop_index(op.f("ix_admin_sessions_session_token"), table_name="admin_sessions")
    op.drop_index(op.f("ix_admin_sessions_login_at"), table_name="admin_sessions")
    op.drop_index(op.f("ix_admin_sessions_is_active"), table_name="admin_sessions")
    op.drop_index(op.f("ix_admin_sessions_id"), table_name="admin_sessions")
    op.drop_index(op.f("ix_admin_sessions_admin_user_id"), table_name="admin_sessions")
    op.drop_table("admin_sessions")
    op.drop_index(op.f("ix_admin_notifications_type"), table_name="admin_notifications")
    op.drop_index(
        op.f("ix_admin_notifications_priority"), table_name="admin_notifications"
    )
    op.drop_index(
        op.f("ix_admin_notifications_is_read"), table_name="admin_notifications"
    )
    op.drop_index(op.f("ix_admin_notifications_id"), table_name="admin_notifications")
    op.drop_index(
        op.f("ix_admin_notifications_action_required"), table_name="admin_notifications"
    )
    op.drop_table("admin_notifications")
    op.drop_index(
        op.f("ix_admin_audit_logs_target_type"), table_name="admin_audit_logs"
    )
    op.drop_index(op.f("ix_admin_audit_logs_target_id"), table_name="admin_audit_logs")
    op.drop_index(op.f("ix_admin_audit_logs_id"), table_name="admin_audit_logs")
    op.drop_index(
        op.f("ix_admin_audit_logs_admin_user_id"), table_name="admin_audit_logs"
    )
    op.drop_index(op.f("ix_admin_audit_logs_action"), table_name="admin_audit_logs")
    op.drop_table("admin_audit_logs")
    op.drop_index(op.f("ix_users_username"), table_name="users")
    op.drop_index(op.f("ix_users_id"), table_name="users")
    op.drop_index(op.f("ix_users_email"), table_name="users")
    op.drop_table("users")
    op.drop_index(
        op.f("ix_marketplace_products_vendor_name"), table_name="marketplace_products"
    )
    op.drop_index(
        op.f("ix_marketplace_products_marketplace_product_id"),
        table_name="marketplace_products",
    )
    op.drop_index(
        op.f("ix_marketplace_products_marketplace"), table_name="marketplace_products"
    )
    op.drop_index(op.f("ix_marketplace_products_id"), table_name="marketplace_products")
    op.drop_index(
        op.f("ix_marketplace_products_gtin"), table_name="marketplace_products"
    )
    op.drop_index(
        op.f("ix_marketplace_products_google_product_category"),
        table_name="marketplace_products",
    )
    op.drop_index(
        op.f("ix_marketplace_products_brand"), table_name="marketplace_products"
    )
    op.drop_index(
        op.f("ix_marketplace_products_availability"), table_name="marketplace_products"
    )
    op.drop_index("idx_marketplace_vendor", table_name="marketplace_products")
    op.drop_index("idx_marketplace_brand", table_name="marketplace_products")
    op.drop_table("marketplace_products")
    # ### end Alembic commands ###
