package com.sonic.cow.service.impl;

import com.sonic.cow.domain.input.AiMessageDelInput;
import com.sonic.cow.service.AiMessageService;
import com.sonic.cow.utils.RedisKeyUtils;
import com.sonic.frog.lib.client.AiChatInfoClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class AiMessageServiceImpl implements AiMessageService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedisKeyUtils redisKeyUtils;
    @Autowired
    private AiChatInfoClient aiChatInfoClient;

    @Override
    public void aiMessageDelete(AiMessageDelInput input, Long currentUserId) {
        List<Long> aiIdList = input.getAiIdList();
        //删除 24小时未聊天时，AI自动给用户发送一条消息
        aiIdList.forEach(aiId -> {
            String ftUserId = currentUserId + "-" + aiId;
            stringRedisTemplate.opsForZSet().remove(redisKeyUtils.notifyUserZSetKey(), ftUserId);
        });
        //更新删除消息了
        aiChatInfoClient.updateIsDelChatted(currentUserId, aiIdList);
    }
}
