package com.fs.chat.service.impl;

import com.fs.chat.domain.ChatSession;
import com.fs.chat.mapper.ChatSessionMapper;
import com.fs.chat.param.ChatSessionListCParam;
import com.fs.chat.service.IChatSessionService;
import com.fs.chat.vo.ChatSessionCVO;
import com.fs.chat.vo.ChatSessionListCVO;
import com.fs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会话Service业务层处理
 *
 * @author fs
 * @date 2024-05-11
 */
@Service
public class ChatSessionServiceImpl implements IChatSessionService
{
    @Autowired
    private ChatSessionMapper chatSessionMapper;

    /**
     * 查询会话
     *
     * @param sessionId 会话主键
     * @return 会话
     */
    @Override
    public ChatSession selectChatSessionBySessionId(Long sessionId)
    {
        return chatSessionMapper.selectChatSessionBySessionId(sessionId);
    }

    /**
     * 查询会话列表
     *
     * @param chatSession 会话
     * @return 会话
     */
    @Override
    public List<ChatSession> selectChatSessionList(ChatSession chatSession)
    {
        return chatSessionMapper.selectChatSessionList(chatSession);
    }

    /**
     * 新增会话
     *
     * @param chatSession 会话
     * @return 结果
     */
    @Override
    public int insertChatSession(ChatSession chatSession)
    {
        chatSession.setCreateTime(DateUtils.getNowDate());
        return chatSessionMapper.insertChatSession(chatSession);
    }

    /**
     * 修改会话
     *
     * @param chatSession 会话
     * @return 结果
     */
    @Override
    public int updateChatSession(ChatSession chatSession)
    {
        chatSession.setUpdateTime(DateUtils.getNowDate());
        return chatSessionMapper.updateChatSession(chatSession);
    }

    /**
     * 批量删除会话
     *
     * @param sessionIds 需要删除的会话主键
     * @return 结果
     */
    @Override
    public int deleteChatSessionBySessionIds(Long[] sessionIds)
    {
        return chatSessionMapper.deleteChatSessionBySessionIds(sessionIds);
    }

    /**
     * 删除会话信息
     *
     * @param sessionId 会话主键
     * @return 结果
     */
    @Override
    public int deleteChatSessionBySessionId(Long sessionId)
    {
        return chatSessionMapper.deleteChatSessionBySessionId(sessionId);
    }


    @Override
    public List<ChatSessionListCVO> selectChatSessionListCVO(ChatSessionListCParam chatSession) {
        return chatSessionMapper.selectChatSessionListCVO(chatSession);
    }

    @Override
    public ChatSessionCVO selectChatSessionCVOBySessionId(Long sessionId) {
        ChatSession map = new ChatSession();
        map.setSessionId(sessionId);
        map.setIsLook(1);
        chatSessionMapper.updateChatSession(map);
        return chatSessionMapper.selectChatSessionCVOBySessionId(sessionId);
    }

    @Override
    public ChatSession selectChatSessionByIds(String userId, String kfId) {
        return chatSessionMapper.selectChatSessionByIds(userId,kfId);
    }
}
