package com.snack.server.module.chat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.snack.server.module.chat.entity.ChatMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 客服消息 Mapper
 */
@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {

    /**
     * 查询会话内当前最大消息序号（用于计算下一条 seq，避免并发冲突）
     */
    @Select("SELECT COALESCE(MAX(seq), 0) FROM chat_message WHERE session_id = #{sessionId}")
    Long maxSeq(@Param("sessionId") Long sessionId);
}
