{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}
{{> AutoGenerated}}

package {{service:javaPackage}};

import com.facebook.thrift.client.*;
import java.util.*;

public class {{service:javaCapitalName}}AsyncReactiveWrapper {{#service:extends}} extends {{service:javaPackage}}.{{service:javaCapitalName}}AsyncReactiveWrapper{{/service:extends}}
    implements {{service:javaCapitalName}}.Reactive {
    private final {{service:javaCapitalName}}.Async _delegate;

    public {{service:javaCapitalName}}AsyncReactiveWrapper({{service:javaCapitalName}}.Async _delegate) {
        {{#service:extends}}super(_delegate);{{/service:extends}}
        this._delegate = _delegate;
    }

    @java.lang.Override
    public void dispose() {
        _delegate.close();
    }

    {{#service:singleRequestFunctions}}
    @java.lang.Override
    public reactor.core.publisher.Mono<{{#function:return_type}}{{> BoxedType}}{{/function:return_type}}> {{function:javaName}}({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}{{^last?}}, {{/last?}}{{/function:args}}) {
        return com.facebook.thrift.util.FutureUtil.toMono(() -> _delegate.{{function:javaName}}({{#function:args}}{{field:javaName}}{{^last?}}, {{/last?}}{{/function:args}}));
    }

    {{/service:singleRequestFunctions}}
    {{#service:streamingFunctions}}
    @java.lang.Override
    public reactor.core.publisher.Flux<{{#function:return_type}}{{> StreamReturnType}}{{/function:return_type}}> {{function:javaName}}({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}{{^last?}}, {{/last?}}{{/function:args}}) {
        throw new UnsupportedOperationException();
    }

    {{/service:streamingFunctions}}
    {{#service:sinkFunctions}}
    @java.lang.Override
    public {{#function:return_type}}{{> SinkReturnType}}{{/function:return_type}} {{function:javaName}}({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}, {{/function:args}} org.reactivestreams.Publisher<{{#function:return_type}}{{#function:sink_elem_type}}{{ >BoxedType}}{{/function:sink_elem_type}}{{/function:return_type}}> payloads) {
        throw new UnsupportedOperationException();
    }

    {{/service:sinkFunctions}}
    {{#service:interactions}}
    public class {{service:name}}Impl implements {{service:name}} {
        private {{interaction:javaParentCapitalName}}.Async.{{service:name}} _delegateInteraction;

        {{service:name}}Impl({{interaction:javaParentCapitalName}}.Async.{{service:name}} delegateInteraction) {
            this._delegateInteraction = delegateInteraction;
        }

        {{#service:singleRequestFunctions}}
        public reactor.core.publisher.Mono<{{#function:return_type}}{{> BoxedType}}{{/function:return_type}}> {{function:javaName}}({{#function:args}}
        final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}{{^last?}},{{/last?}}{{/function:args}}) {
            return com.facebook.thrift.util.FutureUtil.toMono(() -> _delegateInteraction.{{function:javaName}}({{#function:args}}{{field:javaName}}{{^last?}},{{/last?}}{{/function:args}}));
        }

        public reactor.core.publisher.Mono<{{#function:return_type}}{{> BoxedType}}{{/function:return_type}}> {{function:javaName}}({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}, {{/function:args}}RpcOptions rpcOptions) {
            return com.facebook.thrift.util.FutureUtil.toMono(() -> _delegateInteraction.{{function:javaName}}({{#function:args}}{{field:javaName}},{{/function:args}} rpcOptions));
        }

        public reactor.core.publisher.Mono<ResponseWrapper<{{#function:return_type}}{{> BoxedType}}{{/function:return_type}}>> {{function:javaName}}Wrapper({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}, {{/function:args}}RpcOptions rpcOptions) {
            return com.facebook.thrift.util.FutureUtil.toMono(() -> _delegateInteraction.{{function:javaName}}Wrapper({{#function:args}}{{field:javaName}},{{/function:args}} rpcOptions));
        }

        {{/service:singleRequestFunctions}}
        {{#service:streamingFunctions}}
        @java.lang.Override
        public reactor.core.publisher.Flux<{{#function:return_type}}{{> StreamReturnType}}{{/function:return_type}}> {{function:javaName}}({{#function:args}}final {{#field:type}}{{> Type}}{{/field:type}} {{field:javaName}}{{^last?}}, {{/last?}}{{/function:args}}) {
            throw new UnsupportedOperationException();
        }

        {{/service:streamingFunctions}}
        @java.lang.Override
        public void dispose() {
            _delegateInteraction.close();
        }
    }

    public {{service:name}} create{{service:name}}() {
        return new {{service:name}}Impl(_delegate.create{{service:name}}());
    }
    {{^last?}}

    {{/last?}}
    {{/service:interactions}}
}
