"""add_letzshop_historical_import_jobs_table

Revision ID: 204273a59d73
Revises: cb88bc9b5f86
Create Date: 2025-12-19 05:40:53.463341

"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# Removed: from sqlalchemy.dialects import sqlite (using sa.JSON for PostgreSQL)

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


def upgrade() -> None:
    op.create_table("letzshop_historical_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("status", sa.String(length=50), nullable=False),
        sa.Column("current_phase", sa.String(length=20), nullable=True),
        sa.Column("current_page", sa.Integer(), nullable=True),
        sa.Column("total_pages", sa.Integer(), nullable=True),
        sa.Column("shipments_fetched", sa.Integer(), nullable=True),
        sa.Column("orders_processed", sa.Integer(), nullable=True),
        sa.Column("orders_imported", sa.Integer(), nullable=True),
        sa.Column("orders_updated", sa.Integer(), nullable=True),
        sa.Column("orders_skipped", sa.Integer(), nullable=True),
        sa.Column("products_matched", sa.Integer(), nullable=True),
        sa.Column("products_not_found", sa.Integer(), nullable=True),
        sa.Column("confirmed_stats", sa.JSON(), nullable=True),
        sa.Column("declined_stats", sa.JSON(), 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_historical_import_vendor", "letzshop_historical_import_jobs", ["vendor_id", "status"], unique=False)
    op.create_index(op.f("ix_letzshop_historical_import_jobs_id"), "letzshop_historical_import_jobs", ["id"], unique=False)
    op.create_index(op.f("ix_letzshop_historical_import_jobs_vendor_id"), "letzshop_historical_import_jobs", ["vendor_id"], unique=False)


def downgrade() -> None:
    op.drop_index(op.f("ix_letzshop_historical_import_jobs_vendor_id"), table_name="letzshop_historical_import_jobs")
    op.drop_index(op.f("ix_letzshop_historical_import_jobs_id"), table_name="letzshop_historical_import_jobs")
    op.drop_index("idx_historical_import_vendor", table_name="letzshop_historical_import_jobs")
    op.drop_table("letzshop_historical_import_jobs")
