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

import com.seer.teach.common.dto.mq.StringDTO;
import com.seer.teach.common.enums.im.LargeModuleTopTagEnum;
import com.seer.teach.common.enums.MessagePushStatusEnums;
import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.netty.common.proto.MessageType;
import com.seer.teach.netty.im.handler.mq.ImLargeModuleHandler;
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>
 *
 * </p >
 *
 * @author Captain
 * @since 2025-10-08 13:36
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ReceiveStudyDataStreamErrorHandler implements ImLargeModuleHandler<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.getMsg()
        );
        boolean result = redisAudioChannelSubscriber.removeChannel(messageBody.getData());
        log.info("移除音频频道消费者 结果: {}", result);
    }

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

    @Override
    public String getTag() {
        return LargeModuleTopTagEnum.RECEIVE_STUDY_DATA_STREAM_ERROR.getTag();
    }
}
