package com.cmvr.framework.websocket.handler;

import com.cmvr.framework.websocket.annotation.WSMessageType;
import com.cmvr.framework.websocket.enums.WSMessageTypeEnum;
import com.cmvr.framework.websocket.manager.ChannelSubscriptionManager;
import com.cmvr.framework.websocket.message.WSChannelSubscriptionMessage;
import com.cmvr.framework.websocket.service.GrpcClientService;
import org.springframework.stereotype.Component;


@Component
@WSMessageType(value = WSMessageTypeEnum.CHANNEL_SUBSCRIPTION, messageClass = WSChannelSubscriptionMessage.class)
public class ChannelSubscriptionMessageHandler extends BaseChannelSubscribeHandler {

    public ChannelSubscriptionMessageHandler(ChannelSubscriptionManager channelSubscriptionManager, GrpcClientService grpcClientService) {
        super(channelSubscriptionManager, grpcClientService);
    }

    // 当前频道带 / 分段，需要grpc
    @Override
    protected boolean isNeedGrpc(String channel) {
        return channel.contains("/");
    }

    @Override
    protected String[] parseGrpcParam(String channel) {
        return channel.split("/");
    }

}
