"""Drop automation_level column from v3_plans.

This migration removes the legacy ``automation_level`` column and its
CHECK constraint from the ``v3_plans`` table.  Automation behavior is
now controlled exclusively by the ``automation_profile`` JSON column.

Revision ID: a6_002_drop_automation_level
Revises: c3_001_actor_registry
Create Date: 2026-02-19 10:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

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


def upgrade() -> None:
    """Drop automation_level column and CHECK constraint from v3_plans."""
    with op.batch_alter_table("v3_plans") as batch_op:
        batch_op.drop_constraint("ck_v3_plans_automation", type_="check")
        batch_op.drop_column("automation_level")


def downgrade() -> None:
    """Restore automation_level column with CHECK constraint on v3_plans."""
    with op.batch_alter_table("v3_plans") as batch_op:
        batch_op.add_column(
            sa.Column(
                "automation_level",
                sa.String(30),
                nullable=False,
                server_default="manual",
            ),
        )
        batch_op.create_check_constraint(
            "ck_v3_plans_automation",
            "automation_level IN ('manual', 'review_before_apply', 'full_automation')",
        )
