-- 私聊会话表
CREATE TABLE IF NOT EXISTS `eb_conversation` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '会话ID',
  `user1_id` int(11) NOT NULL COMMENT '用户1的ID',
  `user2_id` int(11) NOT NULL COMMENT '用户2的ID',
  `last_message` varchar(500) DEFAULT '' COMMENT '最后一条消息内容',
  `last_message_time` datetime DEFAULT NULL COMMENT '最后一条消息时间',
  `user1_unread_count` int(11) DEFAULT 0 COMMENT '用户1的未读数量',
  `user2_unread_count` int(11) DEFAULT 0 COMMENT '用户2的未读数量',
  `user1_deleted` tinyint(1) DEFAULT 0 COMMENT '用户1是否删除会话',
  `user2_deleted` tinyint(1) DEFAULT 0 COMMENT '用户2是否删除会话',
  `user1_muted` tinyint(1) DEFAULT 0 COMMENT '用户1是否静音',
  `user2_muted` tinyint(1) DEFAULT 0 COMMENT '用户2是否静音',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_user1_id` (`user1_id`),
  KEY `idx_user2_id` (`user2_id`),
  KEY `idx_last_message_time` (`last_message_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私聊会话表';

-- 私信消息表
CREATE TABLE IF NOT EXISTS `eb_private_message` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '消息ID',
  `conversation_id` bigint(20) NOT NULL COMMENT '会话ID',
  `sender_id` int(11) NOT NULL COMMENT '发送者用户ID',
  `receiver_id` int(11) NOT NULL COMMENT '接收者用户ID',
  `content` text COMMENT '消息内容',
  `message_type` varchar(20) DEFAULT 'text' COMMENT '消息类型: text, image, file',
  `status` varchar(20) DEFAULT 'sent' COMMENT '消息状态: sending, sent, read',
  `sender_deleted` tinyint(1) DEFAULT 0 COMMENT '发送者是否删除',
  `receiver_deleted` tinyint(1) DEFAULT 0 COMMENT '接收者是否删除',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `read_time` datetime DEFAULT NULL COMMENT '已读时间',
  PRIMARY KEY (`id`),
  KEY `idx_conversation_id` (`conversation_id`),
  KEY `idx_sender_id` (`sender_id`),
  KEY `idx_receiver_id` (`receiver_id`),
  KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私信消息表';
