package com.njcn.msgpush.module.push.dal.redis;

import com.njcn.msgpush.module.push.dal.dataobject.message.MessageRecordDO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author caozehui
 * @data 2026-04-03
 */
@Component
@RequiredArgsConstructor
public class MessageConfirmRedisDAO {
    private final RedisTemplate<String, String> redisTemplate;

    private static final String CONFIRM_QUEUE_KEY_PREFIX = "msPush:confirm_queue:";

    private String getConfirmQueueKey(Long messageId) {
        return CONFIRM_QUEUE_KEY_PREFIX + messageId;
    }

    public boolean addToConfirmQueue(MessageRecordDO message) {
        String key = getConfirmQueueKey(message.getId());
        return redisTemplate.opsForValue().setIfAbsent(key, "");
    }

    public boolean removeFromConfirmQueue(MessageRecordDO message) {
        String key = getConfirmQueueKey(message.getId());
        return redisTemplate.delete(key);
    }
}
