CREATE TABLE IF NOT EXISTS lobster_conversation_change_event (
    id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
    company_id BIGINT NOT NULL COMMENT '企业ID',
    contact_id BIGINT NULL COMMENT '客户/联系人ID',
    channel_type VARCHAR(32) NULL COMMENT '渠道类型',
    event_type VARCHAR(64) NOT NULL COMMENT '突发变动类型',
    old_state_json JSON NULL COMMENT '原上下文/计划快照',
    new_state_json JSON NULL COMMENT '新状态/计划快照',
    detected_intent VARCHAR(128) NULL COMMENT '识别意图',
    suggested_action VARCHAR(64) NULL COMMENT '建议动作',
    confidence DECIMAL(6,4) NULL COMMENT '置信度',
    risk_level VARCHAR(32) NULL COMMENT '风险等级',
    need_human_confirm TINYINT DEFAULT 0 COMMENT '是否需要人工确认',
    handled_status VARCHAR(32) DEFAULT 'pending' COMMENT '处理状态',
    handle_result VARCHAR(512) NULL COMMENT '处理结果',
    message_text TEXT NULL COMMENT '触发消息',
    create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (id),
    KEY idx_company_contact_time (company_id, contact_id, create_time),
    KEY idx_company_event_time (company_id, event_type, create_time),
    KEY idx_company_status (company_id, handled_status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='客户沟通突发变动事件表';
