package com.seer.teach.netty.im.handler.mq.impl.redisChannelPush;

import com.seer.teach.common.dto.mq.StringDTO;
import com.seer.teach.common.enums.MessagePushStatusEnums;
import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.enums.im.RedisChannelPushTopTagEnum;
import com.seer.teach.netty.common.proto.MessageType;
import com.seer.teach.netty.im.handler.mq.ImRedisChannelPushHandler;
import com.seer.teach.netty.im.utils.ImUtils;
import com.seer.teach.netty.im.utils.RedisAudioChannelSubscriber;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 推送音频数据至Tv端
 * </p>
 *
 * @author Captain
 * @since 2025-07-17 22:13
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class PushLlmAudioErrorHandler implements ImRedisChannelPushHandler<StringDTO> {

    private final RedisAudioChannelSubscriber redisAudioChannelSubscriber;

    @Override
    public void handle(StringDTO messageBody, String device) {
        ImUtils.pushSingleChatToDeviceWithAck(device,
                MessagePushStatusEnums.SUCCESS.getCode(),
                MessageType.MessageContentType.RECEIVE_STUDY_DATA_STREAM_ERROR.getMsgContentType(),
                ResultCodeEnum.REQUEST_LLM_FAIL.getCode());
        boolean result = redisAudioChannelSubscriber.removeChannel(messageBody.getData());
        log.info("移除 {} 音频频道消费者 结果: {}", messageBody.getData(), result);
    }

    @Override
    public Class<StringDTO> getType() {
        return StringDTO.class;
    }

    @Override
    public String getTag() {
        return RedisChannelPushTopTagEnum.PUSH_LLM_AUDIO_ERROR.getTag();
    }

}
