package com.fs.chat.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fs.chat.domain.ChatMsgLogs;
import com.fs.chat.mapper.ChatMsgLogsMapper;
import com.fs.chat.param.ChatMsgListAParam;
import com.fs.chat.param.ChatMsgListCParam;
import com.fs.chat.vo.ChatMsgListAVO;
import com.fs.chat.vo.ChatMsgListCVO;
import com.fs.chat.vo.ChatMsgVO;
import com.fs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.chat.mapper.ChatMsgMapper;
import com.fs.chat.domain.ChatMsg;
import com.fs.chat.service.IChatMsgService;

/**
 * 聊天消息记录Service业务层处理
 *
 * @author fs
 * @date 2024-04-19
 */
@Service
public class ChatMsgServiceImpl implements IChatMsgService
{
    @Autowired
    private ChatMsgMapper chatMsgMapper;
    /**
     * 查询聊天消息记录
     *
     * @param msgId 聊天消息记录主键
     * @return 聊天消息记录
     */
    @Override
    public ChatMsg selectChatMsgByMsgId(Long msgId)
    {
        return chatMsgMapper.selectChatMsgByMsgId(msgId);
    }

    /**
     * 查询聊天消息记录列表
     *
     * @param chatMsg 聊天消息记录
     * @return 聊天消息记录
     */
    @Override
    public List<ChatMsg> selectChatMsgList(ChatMsg chatMsg)
    {
        return chatMsgMapper.selectChatMsgList(chatMsg);
    }

    /**
     * 新增聊天消息记录
     *
     * @param chatMsg 聊天消息记录
     * @return 结果
     */
    @Override
    public int insertChatMsg(ChatMsg chatMsg)
    {
        chatMsg.setCreateTime(DateUtils.getNowDate());
        return chatMsgMapper.insertChatMsg(chatMsg);
    }

    /**
     * 修改聊天消息记录
     *
     * @param chatMsg 聊天消息记录
     * @return 结果
     */
    @Override
    public int updateChatMsg(ChatMsg chatMsg)
    {

        return chatMsgMapper.updateChatMsg(chatMsg);
    }

    /**
     * 批量删除聊天消息记录
     *
     * @param msgIds 需要删除的聊天消息记录主键
     * @return 结果
     */
    @Override
    public int deleteChatMsgByMsgIds(Long[] msgIds)
    {
        return chatMsgMapper.deleteChatMsgByMsgIds(msgIds);
    }

    /**
     * 删除聊天消息记录信息
     *
     * @param msgId 聊天消息记录主键
     * @return 结果
     */
    @Override
    public int deleteChatMsgByMsgId(Long msgId)
    {
        return chatMsgMapper.deleteChatMsgByMsgId(msgId);
    }

    @Override
    public List<ChatMsgListCVO> selectChatMsgListCVO(ChatMsgListCParam param) {
        return chatMsgMapper.selectChatMsgListCVO(param);
    }

    @Override
    public int checkMsg(String extId) {
        return chatMsgMapper.checkMsg(extId);
    }

    @Override
    public Map<String,Object> selectAllChatMsgByMsgId(Long msgId) {
        ChatMsgVO chatMsg = chatMsgMapper.selectChatMsgByMsgVOId(msgId);
        List<ChatMsg> chatMsgList = chatMsgMapper.selectAllChatMsgByUserIdAndRoleId(chatMsg.getUserId(), chatMsg.getRoleId());
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg",chatMsg);
        map.put("msgList",chatMsgList);
        return map;
    }

    @Override
    public String selectUserContent(Long msgId, String userId, Long roleId) {
        return chatMsgMapper.selectUserContent(msgId,userId,roleId);
    }

    @Override
    public List<ChatMsgVO> selectChatMsgBySessionId(Long sessionId) {
        return chatMsgMapper.selectChatMsgBySessionId(sessionId);
    }

    @Override
    public ChatMsgVO selectChatMsgVOByMsgId(Long msgId) {
        ChatMsgVO vo = chatMsgMapper.selectChatMsgByMsgVOId(msgId);
        String userContent = chatMsgMapper.selectUserContent(vo.getMsgId(),vo.getUserId(),vo.getRoleId());
        vo.setUserContent(userContent);
        return vo;
    }

    @Override
    public List<ChatMsgListAVO> selectChatMsgListAVO(ChatMsgListAParam param) {
        return chatMsgMapper.selectChatMsgListAVO(param);
    }
}
