/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */

package test.fixtures.interactions;

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

public class InteractWithSharedBlockingReactiveWrapper 
    implements InteractWithShared.Reactive {
    private final InteractWithShared _delegate;

    public InteractWithSharedBlockingReactiveWrapper(InteractWithShared _delegate) {
        
        this._delegate = _delegate;
    }

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

    @java.lang.Override
    public reactor.core.publisher.Mono<test.fixtures.another_interactions.DoSomethingResult> doSomeSimilarThings() {
        reactor.core.publisher.Mono<test.fixtures.another_interactions.DoSomethingResult> _m = reactor.core.publisher.Mono.create(_sink -> {
            try {
                reactor.util.context.ContextView _contextView = _sink.contextView();
                com.facebook.nifty.core.RequestContext
                    .tryContextView(_contextView)
                    .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                _sink.success(_delegate.doSomeSimilarThings());
            } catch (Throwable _e) {
                _sink.error(_e);
            }
        });

        if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
            _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
        }

        return _m;
    }

    public class MyInteractionImpl implements MyInteraction {
        private InteractWithShared.MyInteraction _delegateInteraction;

        MyInteractionImpl(InteractWithShared.MyInteraction delegateInteraction) {
            this._delegateInteraction = delegateInteraction;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Integer> frobnicate() {
                reactor.core.publisher.Mono<Integer> _m = reactor.core.publisher.Mono.create(_sink -> {
                    try {
                        reactor.util.context.ContextView _contextView = _sink.contextView();
                        com.facebook.nifty.core.RequestContext
                            .tryContextView(_contextView)
                            .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                        _sink.success(_delegateInteraction.frobnicate());
                    } catch (Throwable _e) {
                        _sink.error(_e);
                    }
                });

                if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
                    _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
                }

                return _m;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Integer> frobnicate(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<ResponseWrapper<Integer>> frobnicateWrapper(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Void> ping() {

                reactor.core.publisher.Mono<Void> _m = reactor.core.publisher.Mono.<Void>create(_sink -> {
                    try {
                        reactor.util.context.ContextView _contextView = _sink.contextView();
                        com.facebook.nifty.core.RequestContext
                            .tryContextView(_contextView)
                            .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                        _delegateInteraction.ping();
                        _sink.success();
                    } catch (Throwable _e) {
                        throw reactor.core.Exceptions.propagate(_e);
                    }
                });

                if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
                    _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
                }

                return _m;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Void> ping(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<ResponseWrapper<Void>> pingWrapper(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Flux<Boolean> truthify() {
            throw new UnsupportedOperationException();
        }

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

    public MyInteraction createMyInteraction() {
        return new MyInteractionImpl(_delegate.createMyInteraction());
    }

    public class SharedInteractionImpl implements SharedInteraction {
        private InteractWithShared.SharedInteraction _delegateInteraction;

        SharedInteractionImpl(InteractWithShared.SharedInteraction delegateInteraction) {
            this._delegateInteraction = delegateInteraction;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Integer> init() {
                reactor.core.publisher.Mono<Integer> _m = reactor.core.publisher.Mono.create(_sink -> {
                    try {
                        reactor.util.context.ContextView _contextView = _sink.contextView();
                        com.facebook.nifty.core.RequestContext
                            .tryContextView(_contextView)
                            .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                        _sink.success(_delegateInteraction.init());
                    } catch (Throwable _e) {
                        _sink.error(_e);
                    }
                });

                if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
                    _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
                }

                return _m;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Integer> init(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<ResponseWrapper<Integer>> initWrapper(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<test.fixtures.another_interactions.DoSomethingResult> doSomething() {
                reactor.core.publisher.Mono<test.fixtures.another_interactions.DoSomethingResult> _m = reactor.core.publisher.Mono.create(_sink -> {
                    try {
                        reactor.util.context.ContextView _contextView = _sink.contextView();
                        com.facebook.nifty.core.RequestContext
                            .tryContextView(_contextView)
                            .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                        _sink.success(_delegateInteraction.doSomething());
                    } catch (Throwable _e) {
                        _sink.error(_e);
                    }
                });

                if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
                    _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
                }

                return _m;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<test.fixtures.another_interactions.DoSomethingResult> doSomething(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<ResponseWrapper<test.fixtures.another_interactions.DoSomethingResult>> doSomethingWrapper(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Void> tearDown() {

                reactor.core.publisher.Mono<Void> _m = reactor.core.publisher.Mono.<Void>create(_sink -> {
                    try {
                        reactor.util.context.ContextView _contextView = _sink.contextView();
                        com.facebook.nifty.core.RequestContext
                            .tryContextView(_contextView)
                            .ifPresent(com.facebook.nifty.core.RequestContexts::setCurrentContext);
                        _delegateInteraction.tearDown();
                        _sink.success();
                    } catch (Throwable _e) {
                        throw reactor.core.Exceptions.propagate(_e);
                    }
                });

                if (!com.facebook.thrift.util.resources.RpcResources.isForceExecutionOffEventLoop()) {
                    _m = _m.subscribeOn(com.facebook.thrift.util.resources.RpcResources.getOffLoopScheduler());
                }

                return _m;
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<Void> tearDown(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

        @java.lang.Override
        public reactor.core.publisher.Mono<ResponseWrapper<Void>> tearDownWrapper(RpcOptions rpcOptions) {
            throw new UnsupportedOperationException();
        }

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

    public SharedInteraction createSharedInteraction() {
        return new SharedInteractionImpl(_delegate.createSharedInteraction());
    }
}
