"""drop_legacy_return_counters

Revision ID: 9f3c2d1b7a11
Revises: 4ad64605fad2
Create Date: 2026-03-20 15:10:00.000000

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "9f3c2d1b7a11"
down_revision: Union[str, Sequence[str], None] = "7937209f9718"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Drop legacy quantity counters replaced by balance/discharge ledger."""
    op.drop_column("item_line_quantities", "quantity_returned_temp", schema="a76")
    op.drop_column("item_line_quantities", "quantity_returned", schema="a76")
    op.drop_column("item_line_quantities", "quantity_existence", schema="a76")


def downgrade() -> None:
    """Restore legacy quantity counters."""
    op.add_column(
        "item_line_quantities",
        sa.Column("quantity_existence", sa.Numeric(precision=19, scale=8), nullable=True),
        schema="a76",
    )
    op.add_column(
        "item_line_quantities",
        sa.Column("quantity_returned", sa.Numeric(precision=19, scale=8), nullable=True),
        schema="a76",
    )
    op.add_column(
        "item_line_quantities",
        sa.Column("quantity_returned_temp", sa.Numeric(precision=19, scale=8), nullable=True),
        schema="a76",
    )
