"""Add new features: callback fields and clinic_id

Revision ID: 9bd0518d29b3
Revises: 001_production_baseline
Create Date: 2025-09-06 14:26:24.719045

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '9bd0518d29b3'
down_revision = '001_production_baseline'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # Add new fields to callback_records table
    with op.batch_alter_table('callback_records', schema=None) as batch_op:
        batch_op.add_column(sa.Column('next_appointment_time', sa.Text(), nullable=True, comment='下次预约时间'))
        batch_op.add_column(sa.Column('failure_reason', sa.Text(), nullable=True, comment='不成功的原因'))
        batch_op.add_column(sa.Column('abandon_reason', sa.Text(), nullable=True, comment='放弃回访的原因'))
        batch_op.add_column(sa.Column('ai_feedback_type', sa.String(length=100), nullable=True, comment='AI错误反馈类型'))
        batch_op.add_column(sa.Column('failure_reason_note', sa.Text(), nullable=True, comment='不成功备注'))
        batch_op.add_column(sa.Column('abandon_reason_note', sa.Text(), nullable=True, comment='放弃回访备注'))
        batch_op.add_column(sa.Column('ai_feedback_note', sa.Text(), nullable=True, comment='AI反馈备注'))
        batch_op.add_column(sa.Column('callback_status', sa.String(length=50), nullable=False, server_default='已回访', comment='回访状态'))

    # Add clinic_id to patients table
    with op.batch_alter_table('patients', schema=None) as batch_op:
        batch_op.add_column(sa.Column('clinic_id', sa.Integer(), nullable=True, comment='诊所ID'))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # Remove clinic_id from patients table
    with op.batch_alter_table('patients', schema=None) as batch_op:
        batch_op.drop_column('clinic_id')

    # Remove new fields from callback_records table
    with op.batch_alter_table('callback_records', schema=None) as batch_op:
        batch_op.drop_column('callback_status')
        batch_op.drop_column('ai_feedback_note')
        batch_op.drop_column('abandon_reason_note')
        batch_op.drop_column('failure_reason_note')
        batch_op.drop_column('ai_feedback_type')
        batch_op.drop_column('abandon_reason')
        batch_op.drop_column('failure_reason')
        batch_op.drop_column('next_appointment_time')
    # ### end Alembic commands ###
