-- ============================================================
-- 10_support_feedback_messages.sql
-- 问题反馈对话消息 + feedbacks.updated_at
-- ============================================================

-- 工单表增加最后更新时间（列表排序、对话活跃时间）
ALTER TABLE `www_support_feedbacks`
  ADD COLUMN `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `created_at`;

-- 对话消息表
CREATE TABLE IF NOT EXISTS `www_support_feedback_messages` (
  `id`           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `feedback_id`  BIGINT UNSIGNED NOT NULL COMMENT '关联 www_support_feedbacks.id',
  `sender_type`  VARCHAR(10)   NOT NULL COMMENT 'user / staff',
  `sender_id`    BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'staff 时为 dashboard_user.id',
  `sender_name`  VARCHAR(100)  NOT NULL DEFAULT '' COMMENT '显示名快照',
  `content`      TEXT          NOT NULL COMMENT '消息内容',
  `created_at`   DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_feedback_created` (`feedback_id`, `created_at`),
  KEY `idx_feedback_id` (`feedback_id`, `id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  COMMENT='官网问题反馈对话消息';
