package com.seer.teach.common.cache;

import com.seer.teach.common.dto.mq.LlmChatDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * Redis 发布器（Publisher）
 * 将 LlmChatDTO 消息发布到指定设备频道
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class LlmAudioPublisher {

    /**
     * Redis频道前缀
     */
    private static final String CHANNEL_PREFIX = "llmAudioChannel:";

    private final RedisTemplate<String, Object> redisTemplate;

    public static String getChannel(String channelName) {
        return CHANNEL_PREFIX + channelName;
    }

    /**
     * 发布音频消息到指定设备频道
     *
     * @param channelName 队列名称
     * @param message     消息对象
     */
    public void publish(String channelName, LlmChatDTO message) {
        redisTemplate.convertAndSend(channelName, message);
    }
}
