"""process auto-apply settings + review mode (#1464) — system-tag refactor

The system-tag behavior refactor gives `wip` / `editor screenshot` (the PROCESS
group) their own provisional auto-apply, parallel to the presentation (chrome)
sweep. MLSettings gains three knobs: enabled (OFF by default — a new whole-library
auto-tagger is opt-in), the flat apply threshold, and the ring-loud conflict
threshold. presentation_review gains a `mode` column so one review surface serves
both chrome and process flags (existing rows backfill 'chrome'). server_defaults
so the existing rows fill cleanly.

Revision ID: 0086
Revises: 0085
Create Date: 2026-07-13
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0086"
down_revision: Union[str, None] = "0085"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "ml_settings",
        sa.Column(
            "process_auto_apply_enabled", sa.Boolean(), nullable=False,
            server_default=sa.text("false"),
        ),
    )
    op.add_column(
        "ml_settings",
        sa.Column(
            "process_auto_apply_threshold", sa.Float(), nullable=False,
            server_default="0.90",
        ),
    )
    op.add_column(
        "ml_settings",
        sa.Column(
            "process_conflict_threshold", sa.Float(), nullable=False,
            server_default="0.50",
        ),
    )
    op.add_column(
        "presentation_review",
        sa.Column(
            "mode", sa.String(16), nullable=False,
            server_default="chrome",
        ),
    )


def downgrade() -> None:
    op.drop_column("presentation_review", "mode")
    op.drop_column("ml_settings", "process_conflict_threshold")
    op.drop_column("ml_settings", "process_auto_apply_threshold")
    op.drop_column("ml_settings", "process_auto_apply_enabled")
