package com.seer.teach.netty.im.handler.im.business;

import com.seer.teach.netty.common.annotation.ImMessageType;
import com.seer.teach.netty.common.proto.MessageProtobuf;
import com.seer.teach.netty.im.handler.im.ImMessageContentHandler;
import com.seer.teach.netty.im.handler.im.ImMsgHandler;
import com.seer.teach.netty.im.registry.TvSingleChatBusinessHandlerRegistry;
import io.netty.channel.ChannelHandlerContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @Author: Captain
 * @Description: 单聊业务处理
 * @Date: 2025-05-23 14:50
 */
@Service
@Slf4j
@Component
@ImMessageType(2001)
@RequiredArgsConstructor
public class ImSingleChatHandler implements ImMsgHandler {

    private final TvSingleChatBusinessHandlerRegistry tvSingleChatBusinessHandlerRegistry;

    @Override
    public void handle(ChannelHandlerContext ctx, MessageProtobuf.Msg msg) {
        ImMessageContentHandler handler = tvSingleChatBusinessHandlerRegistry.getHandler(msg.getHead().getMsgContentType());
        if (handler != null) {
            handler.handleWithLog(ctx, msg);
        } else {
            log.info("未处理的消息类型: {}", msg.getHead().getMsgContentType());
        }
    }
}
