"""Add size table and update product structure

Revision ID: 9773b0186faa
Revises: ef40913679bd
Create Date: 2025-03-16 20:30:39.057254

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '9773b0186faa'
down_revision: Union[str, None] = 'ef40913679bd'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('sizes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('code', sa.String(), nullable=False),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('code')
    )
    op.create_index(op.f('ix_sizes_id'), 'sizes', ['id'], unique=False)
    op.add_column('product_variants', sa.Column('size_id', sa.Integer(), nullable=False))
    op.create_foreign_key(None, 'product_variants', 'sizes', ['size_id'], ['id'])
    op.drop_column('product_variants', 'discount_price')
    op.drop_column('product_variants', 'name')
    op.drop_column('product_variants', 'price')
    op.add_column('products', sa.Column('price', sa.Float(), nullable=False))
    op.add_column('products', sa.Column('discount_price', sa.Float(), nullable=True))
    op.add_column('products', sa.Column('care_instructions', sa.JSON(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('products', 'care_instructions')
    op.drop_column('products', 'discount_price')
    op.drop_column('products', 'price')
    op.add_column('product_variants', sa.Column('price', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False))
    op.add_column('product_variants', sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False))
    op.add_column('product_variants', sa.Column('discount_price', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'product_variants', type_='foreignkey')
    op.drop_column('product_variants', 'size_id')
    op.drop_index(op.f('ix_sizes_id'), table_name='sizes')
    op.drop_table('sizes')
    # ### end Alembic commands ###
