// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.handler.codec.http3;

import io.netty.channel.ChannelHandlerContext;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import io.netty.channel.ChannelHandler;
import java.util.function.LongFunction;

final class Http3UnidirectionalStreamInboundClientHandler extends Http3UnidirectionalStreamInboundHandler
{
    private final LongFunction<ChannelHandler> pushStreamHandlerFactory;
    
    Http3UnidirectionalStreamInboundClientHandler(final Http3FrameCodec.Http3FrameCodecFactory codecFactory, final Http3ControlStreamInboundHandler localControlStreamHandler, final Http3ControlStreamOutboundHandler remoteControlStreamHandler, @Nullable final LongFunction<ChannelHandler> unknownStreamHandlerFactory, @Nullable final LongFunction<ChannelHandler> pushStreamHandlerFactory, final Supplier<ChannelHandler> qpackEncoderHandlerFactory, final Supplier<ChannelHandler> qpackDecoderHandlerFactory) {
        super(codecFactory, localControlStreamHandler, remoteControlStreamHandler, unknownStreamHandlerFactory, qpackEncoderHandlerFactory, qpackDecoderHandlerFactory);
        this.pushStreamHandlerFactory = (LongFunction<ChannelHandler>)((pushStreamHandlerFactory == null) ? (__ -> ReleaseHandler.INSTANCE) : pushStreamHandlerFactory);
    }
    
    @Override
    void initPushStream(final ChannelHandlerContext ctx, final long pushId) {
        final Long maxPushId = this.remoteControlStreamHandler.sentMaxPushId();
        if (maxPushId == null) {
            Http3CodecUtils.connectionError(ctx, Http3ErrorCode.H3_ID_ERROR, "Received push stream before sending MAX_PUSH_ID frame.", false);
        }
        else if (maxPushId < pushId) {
            Http3CodecUtils.connectionError(ctx, Http3ErrorCode.H3_ID_ERROR, "Received push stream with ID " + pushId + " greater than the max push ID " + maxPushId + '.', false);
        }
        else {
            final ChannelHandler pushStreamHandler = this.pushStreamHandlerFactory.apply(pushId);
            ctx.pipeline().replace(this, null, pushStreamHandler);
        }
    }
}
