"""Rename automation profile task-type threshold columns.

Renames all 11 task-type confidence threshold columns in the
``automation_profiles`` table from phase-transition semantics to the
spec-defined task-type semantics.

Revision ID: m5_001_rename_profile_fields
Revises: m4_003_plan_env_columns
Create Date: 2026-03-24 10:00:00

"""

from collections.abc import Sequence

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "m5_001_rename_profile_fields"
down_revision: str | Sequence[str] | None = "m4_003_plan_env_columns"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

# Mapping of (old_name, new_name) for every renamed column.
_COLUMN_RENAMES: list[tuple[str, str]] = [
    ("auto_strategize", "decompose_task"),
    ("auto_execute", "create_tool"),
    ("auto_apply", "select_tool"),
    ("auto_decisions_strategize", "edit_code"),
    ("auto_decisions_execute", "execute_command"),
    ("auto_validation_fix", "create_file"),
    ("auto_strategy_revision", "delete_content"),
    ("auto_reversion_from_apply", "access_network"),
    ("auto_child_plans", "install_dependency"),
    ("auto_retry_transient", "modify_config"),
    ("auto_checkpoint_restore", "approve_plan"),
]


def upgrade() -> None:
    """Rename threshold columns to spec-defined task-type names."""
    with op.batch_alter_table("automation_profiles") as batch_op:
        for old_name, new_name in _COLUMN_RENAMES:
            batch_op.alter_column(old_name, new_column_name=new_name)


def downgrade() -> None:
    """Revert threshold columns to phase-transition names."""
    with op.batch_alter_table("automation_profiles") as batch_op:
        for old_name, new_name in _COLUMN_RENAMES:
            batch_op.alter_column(new_name, new_column_name=old_name)
