"""drop artist + copyright ml thresholds; lower general default to 0.50

Revision ID: 0029
Revises: 0028
Create Date: 2026-06-01

Operator-flagged 2026-06-01: the view modal's Suggestions panel hides
most general-category predictions because the default threshold is
0.95. Lowering the default to 0.50 (matches character) so general
suggestions surface more aggressively; the value remains tunable in
Settings → ML.

Same change retires two ML suggestion categories whose Tag.kind
surfaces are unused:

- `artist`: retired in FC-2d-vii-c — artist identity is acquisition-
  derived (image_record.artist_id), never ML-inferred. The threshold
  column was a leftover from before that retirement.
- `copyright`: retired 2026-06-01 — the app uses `fandom` for the
  franchise/copyright concept (per TagsView.vue's doc comment); no
  Tag rows of kind=copyright exist, and the threshold column never
  fed anything user-visible.

Both columns are dropped from ml_settings; the existing row's
suggestion_threshold_general value is bumped from 0.95 to 0.50 iff
it's still at the old default, so deployed installs pick up the new
UX without overriding any operator tuning.
"""
from typing import Sequence, Union

from alembic import op
from sqlalchemy import text

revision: str = "0029"
down_revision: Union[str, None] = "0028"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Bump the general threshold for installs still at the old default.
    op.execute(text(
        "UPDATE ml_settings "
        "SET suggestion_threshold_general = 0.50 "
        "WHERE id = 1 AND suggestion_threshold_general = 0.95"
    ))
    op.drop_column("ml_settings", "suggestion_threshold_artist")
    op.drop_column("ml_settings", "suggestion_threshold_copyright")


def downgrade() -> None:
    # Restore the columns with their prior defaults. The bump from
    # 0.95 → 0.50 isn't reversible without remembering whether the
    # operator had explicitly set 0.95 (unlikely — that was just the
    # default) so we leave the current general value as-is.
    from sqlalchemy import Column, Float

    op.add_column(
        "ml_settings",
        Column(
            "suggestion_threshold_artist",
            Float, nullable=False, server_default="0.30",
        ),
    )
    op.add_column(
        "ml_settings",
        Column(
            "suggestion_threshold_copyright",
            Float, nullable=False, server_default="0.50",
        ),
    )
