"""Add product units and base unit

Revision ID: d87dfafd3560
Revises: 65a818bbc5d9
Create Date: 2025-12-17 09:08:01.632345

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'd87dfafd3560'
down_revision: Union[str, Sequence[str], None] = '65a818bbc5d9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('product_units',
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('product_id', sa.String(length=36), nullable=False),
    sa.Column('name', sa.Enum('TABLET', 'CAPSULE', 'SACHET', 'PACK', 'BOTTLE', 'VIAL', 'AMPOULE', 'TUBE', 'CREAM', 'OINTMENT', 'GEL', 'SYRUP', 'SUSPENSION', 'DROPS', 'POWDER', 'BOX', 'STRIP', 'CARTON', 'CONTAINER', name='baseunit'), nullable=False),
    sa.Column('multiplier_to_base', sa.Integer(), nullable=False),
    sa.Column('price_per_unit', sa.Float(), nullable=False),
    sa.Column('is_default', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_units_product_id'), 'product_units', ['product_id'], unique=False)
    op.add_column('products', sa.Column('base_unit', sa.Enum('TABLET', 'CAPSULE', 'SACHET', 'PACK', 'BOTTLE', 'VIAL', 'AMPOULE', 'TUBE', 'CREAM', 'OINTMENT', 'GEL', 'SYRUP', 'SUSPENSION', 'DROPS', 'POWDER', 'BOX', 'STRIP', 'CARTON', 'CONTAINER', name='baseunit'), nullable=False, server_default='PACK'))
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('products', 'base_unit')
    op.drop_index(op.f('ix_product_units_product_id'), table_name='product_units')
    op.drop_table('product_units')
    # ### end Alembic commands ###
