package com.fs.fastGpt.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.fs.common.utils.DateUtils;
import com.fs.fastGpt.domain.FastGptChatMsg;
import com.fs.fastGpt.mapper.FastGptChatMsgMapper;
import com.fs.fastGpt.param.FastGptChatMsgListCParam;
import com.fs.fastGpt.service.IFastGptChatMsgService;
import com.fs.fastGpt.vo.FastGptChatMsgCVO;
import com.fs.fastGpt.vo.FastGptChatMsgListCVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 聊天记录Service业务层处理
 *
 * @author fs
 * @date 2024-10-10
 */
@Service
public class FastGptChatMsgServiceImpl implements IFastGptChatMsgService
{
    @Autowired
    private FastGptChatMsgMapper fastGptChatMsgMapper;

    /**
     * 查询聊天记录
     *
     * @param msgId 聊天记录主键
     * @return 聊天记录
     */
    @Override
    public FastGptChatMsg selectFastGptChatMsgByMsgId(Long msgId)
    {
        return fastGptChatMsgMapper.selectFastGptChatMsgByMsgId(msgId);
    }

    /**
     * 查询聊天记录列表
     *
     * @param fastGptChatMsg 聊天记录
     * @return 聊天记录
     */
    @Override
    public List<FastGptChatMsg> selectFastGptChatMsgList(FastGptChatMsg fastGptChatMsg)
    {
        return fastGptChatMsgMapper.selectFastGptChatMsgList(fastGptChatMsg);
    }

    /**
     * 新增聊天记录
     *
     * @param fastGptChatMsg 聊天记录
     * @return 结果
     */
    @Override
    public int insertFastGptChatMsg(FastGptChatMsg fastGptChatMsg)
    {
        fastGptChatMsg.setCreateTime(DateUtils.getNowDate());
        fastGptChatMsg.setMsgId((new Snowflake(1, 1)).nextId());
        return fastGptChatMsgMapper.insertFastGptChatMsg(fastGptChatMsg);
    }

    /**
     * 修改聊天记录
     *
     * @param fastGptChatMsg 聊天记录
     * @return 结果
     */
    @Override
    public int updateFastGptChatMsg(FastGptChatMsg fastGptChatMsg)
    {
        return fastGptChatMsgMapper.updateFastGptChatMsg(fastGptChatMsg);
    }

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

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

    @Override
    public List<FastGptChatMsgCVO> selectFastGptChatMsgCVOBySessionId(Long sessionId) {
        return fastGptChatMsgMapper.selectFastGptChatMsgCVOBySessionId(sessionId);
    }

    @Override
    public List<FastGptChatMsgListCVO> selectFastGptChatMsgListCVO(FastGptChatMsgListCParam param) {
        return fastGptChatMsgMapper.selectFastGptChatMsgListCVO(param);
    }

    @Override
    public FastGptChatMsgCVO selectFastGptChatMsgVOByMsgId(Long msgId) {
        FastGptChatMsgCVO vo = fastGptChatMsgMapper.selectChatMsgByMsgVOId(msgId);
        String userContent = fastGptChatMsgMapper.selectUserContent(vo.getMsgId(),vo.getUserId(),vo.getRoleId());
        vo.setUserContent(userContent);
        return vo;
    }

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

    @Override
    public List<FastGptChatMsg> selectFastGptChatMsgByMsgSessionId(Long sessionId) {
        return fastGptChatMsgMapper.selectFastGptChatMsgByMsgSessionId(sessionId);
    }
}
