"""add missing columns needs_review language_overridden per_language_metrics

Revision ID: c4a3a2f74bfe
Revises: ed310b33f02c
Create Date: 2026-05-14 17:30:36.865269
"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

revision: str = 'c4a3a2f74bfe'
down_revision: str | Sequence[str] | None = 'ed310b33f02c'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # CR1: needs_review + language_overridden on translation_languages
    op.add_column('translation_languages', sa.Column('needs_review', sa.Boolean(), nullable=True,
        comment='Flagged because source language could not be determined'))
    op.add_column('translation_languages', sa.Column('language_overridden', sa.Boolean(), nullable=True,
        comment='User manually overrode the auto-detected source language'))

    # CR1b: needs_review on translation_preview_languages
    op.add_column('translation_preview_languages', sa.Column('needs_review', sa.Boolean(), nullable=True,
        comment='Flagged because source language could not be determined'))

    # CR2: per_language_metrics on translation_metric_snapshots
    op.add_column('translation_metric_snapshots', sa.Column('per_language_metrics', sa.JSON(), nullable=True,
        comment='Per-language cumulative metrics: {lang: {cumulative_tokens, cumulative_cost, runs}}'))


def downgrade() -> None:
    op.drop_column('translation_metric_snapshots', 'per_language_metrics')
    op.drop_column('translation_preview_languages', 'needs_review')
    op.drop_column('translation_languages', 'language_overridden')
    op.drop_column('translation_languages', 'needs_review')
