"""create_product_tables

Revision ID: f51816ef0a57
Revises: 320da61c6e3f
Create Date: 2026-06-03 18:54:15.497373
"""
from collections.abc import Sequence

from alembic import op
import sqlalchemy as sa


revision: str = 'f51816ef0a57'
down_revision: str | None = '320da61c6e3f'
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('product_categories',
    sa.Column('tenant_id', sa.String(length=36), nullable=False),
    sa.Column('name', sa.String(length=200), nullable=False),
    sa.Column('slug', sa.String(length=200), nullable=False),
    sa.Column('parent_id', sa.String(length=36), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.ForeignKeyConstraint(['parent_id'], ['product_categories.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('tenant_id', 'slug', name='uq_tenant_slug')
    )
    op.create_table('products',
    sa.Column('tenant_id', sa.String(length=36), nullable=False),
    sa.Column('category_id', sa.String(length=36), nullable=True),
    sa.Column('title', sa.String(length=500), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('bullet_points', sa.JSON(), nullable=True),
    sa.Column('sku', sa.String(length=100), nullable=True),
    sa.Column('barcode', sa.String(length=100), nullable=True),
    sa.Column('price', sa.DECIMAL(precision=10, scale=2), nullable=False),
    sa.Column('compare_at_price', sa.DECIMAL(precision=10, scale=2), nullable=True),
    sa.Column('currency', sa.String(length=3), server_default='TRY', nullable=False),
    sa.Column('stock_quantity', sa.Integer(), server_default='0', nullable=False),
    sa.Column('stock_status', sa.Enum('in_stock', 'low', 'out_of_stock', name='stock_status'), server_default='in_stock', nullable=False),
    sa.Column('low_stock_threshold', sa.Integer(), server_default='5', nullable=False),
    sa.Column('is_active', sa.Boolean(), server_default='1', nullable=False),
    sa.Column('images', sa.JSON(), nullable=True),
    sa.Column('embedding_status', sa.Enum('pending', 'indexed', 'failed', name='embedding_status'), server_default='pending', nullable=False),
    sa.Column('embedding_updated_at', sa.DateTime(), nullable=True),
    sa.Column('meta', sa.JSON(), nullable=True),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['category_id'], ['product_categories.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_products_deleted_at'), 'products', ['deleted_at'], unique=False)
    op.create_index(op.f('ix_products_tenant_id'), 'products', ['tenant_id'], unique=False)
    op.create_table('product_variants',
    sa.Column('product_id', sa.String(length=36), nullable=False),
    sa.Column('title', sa.String(length=300), nullable=False),
    sa.Column('sku', sa.String(length=100), nullable=True),
    sa.Column('price', sa.DECIMAL(precision=10, scale=2), nullable=False),
    sa.Column('stock_quantity', sa.Integer(), server_default='0', nullable=False),
    sa.Column('attributes', sa.JSON(), nullable=True),
    sa.Column('is_active', sa.Boolean(), server_default='1', nullable=False),
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_variants_product_id'), 'product_variants', ['product_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_product_variants_product_id'), table_name='product_variants')
    op.drop_table('product_variants')
    op.drop_index(op.f('ix_products_tenant_id'), table_name='products')
    op.drop_index(op.f('ix_products_deleted_at'), table_name='products')
    op.drop_table('products')
    op.drop_table('product_categories')
    # ### end Alembic commands ###
