"""add conversation impact fields

Revision ID: 011_add_conversation_impact
Revises: 010_add_agent_otp
Create Date: 2026-06-16

v0.5.6: 补齐 Conversation 模型的 3 个评估字段
- impact_scope (int, default 0): 影响范围(受影响人数)
- is_blocking (bool, default False): 是否阻断员工工作
- emotion_state (str(20), default 'normal'): 情绪状态

为什么需要这个 migration:
  Conversation 模型里加了 impact_scope/is_blocking/emotion_state,
  但缺 alembic migration 落库。坐席发消息时 SQLAlchemy 查
  conversations.* 全字段,报:
    column conversations.impact_scope does not exist

  跟 010_add_agent_otp 是同一类问题(模型新字段无 migration)。
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers
revision = '011_add_conversation_impact'
down_revision = '010_add_agent_otp'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """添加 impact_scope + is_blocking + emotion_state 字段"""
    op.add_column(
        'conversations',
        sa.Column(
            'impact_scope',
            sa.Integer(),
            nullable=False,
            server_default=sa.text('0'),
            comment='影响范围(受影响人数,0=未评估)'
        )
    )
    op.add_column(
        'conversations',
        sa.Column(
            'is_blocking',
            sa.Boolean(),
            nullable=False,
            server_default=sa.text('false'),
            comment='是否阻断员工工作'
        )
    )
    op.add_column(
        'conversations',
        sa.Column(
            'emotion_state',
            sa.String(20),
            nullable=False,
            server_default=sa.text("'normal'"),
            comment='情绪状态(normal/worried/angry/urgent)'
        )
    )


def downgrade() -> None:
    """删除 3 个评估字段"""
    op.drop_column('conversations', 'emotion_state')
    op.drop_column('conversations', 'is_blocking')
    op.drop_column('conversations', 'impact_scope')
