"""Add needs_manual_review flag to receipts table.

Revision ID: 20251230_needs_manual_review
Revises: 20251216_payment_mode
Create Date: 2025-12-30
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '20251230_needs_manual_review'
down_revision = '20251216_payment_mode'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Add needs_manual_review column for OCR validation tracking.

    This column tracks whether a receipt needs manual supervisor review
    based on OCR extraction validation warnings:
    - NULL = not validated yet (old receipts before validation feature)
    - FALSE = validated, no review needed
    - TRUE = validated, needs review
    """
    with op.batch_alter_table('receipts', schema=None) as batch_op:
        batch_op.add_column(
            sa.Column('needs_manual_review', sa.Boolean(), nullable=True)
        )

    # NOTE: We do NOT set a default value for existing rows.
    # NULL indicates the receipt was created before validation was implemented.
    # Only new receipts (created after this migration) will have TRUE/FALSE values.


def downgrade() -> None:
    """Remove needs_manual_review column."""
    with op.batch_alter_table('receipts', schema=None) as batch_op:
        batch_op.drop_column('needs_manual_review')
