/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

    package com.ywt.gapi.taihe.biz;

import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.PathResolver;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.ServerService;
import org.apache.dubbo.rpc.TriRpcStatus;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.rpc.model.StubMethodDescriptor;
import org.apache.dubbo.rpc.model.StubServiceDescriptor;
import org.apache.dubbo.rpc.stub.BiStreamMethodHandler;
import org.apache.dubbo.rpc.stub.ServerStreamMethodHandler;
import org.apache.dubbo.rpc.stub.StubInvocationUtil;
import org.apache.dubbo.rpc.stub.StubInvoker;
import org.apache.dubbo.rpc.stub.StubMethodHandler;
import org.apache.dubbo.rpc.stub.StubSuppliers;
import org.apache.dubbo.rpc.stub.UnaryStubMethodHandler;

import com.google.protobuf.Message;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.concurrent.CompletableFuture;

public final class DubboTaiheBizServiceTriple {

    public static final String SERVICE_NAME = TaiheBizService.SERVICE_NAME;

    private static final StubServiceDescriptor serviceDescriptor = new StubServiceDescriptor(SERVICE_NAME,TaiheBizService.class);

    static {
        org.apache.dubbo.rpc.protocol.tri.service.SchemaDescriptorRegistry.addSchemaDescriptor(SERVICE_NAME,TaiheBizProto.getDescriptor());
        StubSuppliers.addSupplier(SERVICE_NAME, DubboTaiheBizServiceTriple::newStub);
        StubSuppliers.addSupplier(TaiheBizService.JAVA_SERVICE_NAME,  DubboTaiheBizServiceTriple::newStub);
        StubSuppliers.addDescriptor(SERVICE_NAME, serviceDescriptor);
        StubSuppliers.addDescriptor(TaiheBizService.JAVA_SERVICE_NAME, serviceDescriptor);
    }

    @SuppressWarnings("all")
    public static TaiheBizService newStub(Invoker<?> invoker) {
        return new TaiheBizServiceStub((Invoker<TaiheBizService>)invoker);
    }

    private static final StubMethodDescriptor mriBookingMethod = new StubMethodDescriptor("mriBooking",
    com.ywt.gapi.taihe.biz.MriBookingRequest.class, com.ywt.gapi.taihe.biz.MriBaseResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.MriBookingRequest::parseFrom,
    com.ywt.gapi.taihe.biz.MriBaseResponse::parseFrom);

    private static final StubMethodDescriptor mriBookingAsyncMethod = new StubMethodDescriptor("mriBooking",
    com.ywt.gapi.taihe.biz.MriBookingRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.MriBookingRequest::parseFrom,
    com.ywt.gapi.taihe.biz.MriBaseResponse::parseFrom);

    private static final StubMethodDescriptor mriBookingProxyAsyncMethod = new StubMethodDescriptor("mriBookingAsync",
    com.ywt.gapi.taihe.biz.MriBookingRequest.class, com.ywt.gapi.taihe.biz.MriBaseResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.MriBookingRequest::parseFrom,
    com.ywt.gapi.taihe.biz.MriBaseResponse::parseFrom);

    private static final StubMethodDescriptor getScreeningTableMethod = new StubMethodDescriptor("getScreeningTable",
    com.ywt.gapi.taihe.biz.GetScreeningTableRequest.class, com.ywt.gapi.taihe.biz.GetScreeningTableResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor getScreeningTableAsyncMethod = new StubMethodDescriptor("getScreeningTable",
    com.ywt.gapi.taihe.biz.GetScreeningTableRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor getScreeningTableProxyAsyncMethod = new StubMethodDescriptor("getScreeningTableAsync",
    com.ywt.gapi.taihe.biz.GetScreeningTableRequest.class, com.ywt.gapi.taihe.biz.GetScreeningTableResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor submitScreeningTableMethod = new StubMethodDescriptor("submitScreeningTable",
    com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest.class, com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor submitScreeningTableAsyncMethod = new StubMethodDescriptor("submitScreeningTable",
    com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor submitScreeningTableProxyAsyncMethod = new StubMethodDescriptor("submitScreeningTableAsync",
    com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest.class, com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest::parseFrom,
    com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse::parseFrom);

    private static final StubMethodDescriptor getAvailableBookNumMethod = new StubMethodDescriptor("getAvailableBookNum",
    com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest.class, com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse::parseFrom);

    private static final StubMethodDescriptor getAvailableBookNumAsyncMethod = new StubMethodDescriptor("getAvailableBookNum",
    com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse::parseFrom);

    private static final StubMethodDescriptor getAvailableBookNumProxyAsyncMethod = new StubMethodDescriptor("getAvailableBookNumAsync",
    com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest.class, com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest::parseFrom,
    com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse::parseFrom);





    public static class TaiheBizServiceStub implements TaiheBizService{
        private final Invoker<TaiheBizService> invoker;

        public TaiheBizServiceStub(Invoker<TaiheBizService> invoker) {
            this.invoker = invoker;
        }

        @Override
        public com.ywt.gapi.taihe.biz.MriBaseResponse mriBooking(com.ywt.gapi.taihe.biz.MriBookingRequest request){
            return StubInvocationUtil.unaryCall(invoker, mriBookingMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.taihe.biz.MriBaseResponse> mriBookingAsync(com.ywt.gapi.taihe.biz.MriBookingRequest request){
            return StubInvocationUtil.unaryCall(invoker, mriBookingAsyncMethod, request);
        }

        @Override
        public void mriBooking(com.ywt.gapi.taihe.biz.MriBookingRequest request, StreamObserver<com.ywt.gapi.taihe.biz.MriBaseResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, mriBookingMethod , request, responseObserver);
        }
        @Override
        public com.ywt.gapi.taihe.biz.GetScreeningTableResponse getScreeningTable(com.ywt.gapi.taihe.biz.GetScreeningTableRequest request){
            return StubInvocationUtil.unaryCall(invoker, getScreeningTableMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.taihe.biz.GetScreeningTableResponse> getScreeningTableAsync(com.ywt.gapi.taihe.biz.GetScreeningTableRequest request){
            return StubInvocationUtil.unaryCall(invoker, getScreeningTableAsyncMethod, request);
        }

        @Override
        public void getScreeningTable(com.ywt.gapi.taihe.biz.GetScreeningTableRequest request, StreamObserver<com.ywt.gapi.taihe.biz.GetScreeningTableResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, getScreeningTableMethod , request, responseObserver);
        }
        @Override
        public com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse submitScreeningTable(com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest request){
            return StubInvocationUtil.unaryCall(invoker, submitScreeningTableMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse> submitScreeningTableAsync(com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest request){
            return StubInvocationUtil.unaryCall(invoker, submitScreeningTableAsyncMethod, request);
        }

        @Override
        public void submitScreeningTable(com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest request, StreamObserver<com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, submitScreeningTableMethod , request, responseObserver);
        }
        @Override
        public com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse getAvailableBookNum(com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest request){
            return StubInvocationUtil.unaryCall(invoker, getAvailableBookNumMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse> getAvailableBookNumAsync(com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest request){
            return StubInvocationUtil.unaryCall(invoker, getAvailableBookNumAsyncMethod, request);
        }

        @Override
        public void getAvailableBookNum(com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest request, StreamObserver<com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, getAvailableBookNumMethod , request, responseObserver);
        }



    }

    public static abstract class TaiheBizServiceImplBase implements TaiheBizService, ServerService<TaiheBizService> {

        private <T, R> BiConsumer<T, StreamObserver<R>> syncToAsync(java.util.function.Function<T, R> syncFun) {
            return new BiConsumer<T, StreamObserver<R>>() {
                @Override
                public void accept(T t, StreamObserver<R> observer) {
                    try {
                        R ret = syncFun.apply(t);
                        observer.onNext(ret);
                        observer.onCompleted();
                    } catch (Throwable e) {
                        observer.onError(e);
                    }
                }
            };
        }

        @Override
        public final Invoker<TaiheBizService> getInvoker(URL url) {
            PathResolver pathResolver = url.getOrDefaultFrameworkModel()
            .getExtensionLoader(PathResolver.class)
            .getDefaultExtension();
            Map<String,StubMethodHandler<?, ?>> handlers = new HashMap<>();

            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/mriBooking" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/mriBookingAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getScreeningTable" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getScreeningTableAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/submitScreeningTable" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/submitScreeningTableAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getAvailableBookNum" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getAvailableBookNumAsync" );

            BiConsumer<com.ywt.gapi.taihe.biz.MriBookingRequest, StreamObserver<com.ywt.gapi.taihe.biz.MriBaseResponse>> mriBookingFunc = this::mriBooking;
            handlers.put(mriBookingMethod.getMethodName(), new UnaryStubMethodHandler<>(mriBookingFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.MriBookingRequest, StreamObserver<com.ywt.gapi.taihe.biz.MriBaseResponse>> mriBookingAsyncFunc = syncToAsync(this::mriBooking);
            handlers.put(mriBookingProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(mriBookingAsyncFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.GetScreeningTableRequest, StreamObserver<com.ywt.gapi.taihe.biz.GetScreeningTableResponse>> getScreeningTableFunc = this::getScreeningTable;
            handlers.put(getScreeningTableMethod.getMethodName(), new UnaryStubMethodHandler<>(getScreeningTableFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.GetScreeningTableRequest, StreamObserver<com.ywt.gapi.taihe.biz.GetScreeningTableResponse>> getScreeningTableAsyncFunc = syncToAsync(this::getScreeningTable);
            handlers.put(getScreeningTableProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getScreeningTableAsyncFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest, StreamObserver<com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse>> submitScreeningTableFunc = this::submitScreeningTable;
            handlers.put(submitScreeningTableMethod.getMethodName(), new UnaryStubMethodHandler<>(submitScreeningTableFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest, StreamObserver<com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse>> submitScreeningTableAsyncFunc = syncToAsync(this::submitScreeningTable);
            handlers.put(submitScreeningTableProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(submitScreeningTableAsyncFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest, StreamObserver<com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse>> getAvailableBookNumFunc = this::getAvailableBookNum;
            handlers.put(getAvailableBookNumMethod.getMethodName(), new UnaryStubMethodHandler<>(getAvailableBookNumFunc));
            BiConsumer<com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest, StreamObserver<com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse>> getAvailableBookNumAsyncFunc = syncToAsync(this::getAvailableBookNum);
            handlers.put(getAvailableBookNumProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getAvailableBookNumAsyncFunc));




            return new StubInvoker<>(this, url, TaiheBizService.class, handlers);
        }


        @Override
        public com.ywt.gapi.taihe.biz.MriBaseResponse mriBooking(com.ywt.gapi.taihe.biz.MriBookingRequest request){
            throw unimplementedMethodException(mriBookingMethod);
        }

        @Override
        public com.ywt.gapi.taihe.biz.GetScreeningTableResponse getScreeningTable(com.ywt.gapi.taihe.biz.GetScreeningTableRequest request){
            throw unimplementedMethodException(getScreeningTableMethod);
        }

        @Override
        public com.ywt.gapi.taihe.biz.SubmitScreeningTableResponse submitScreeningTable(com.ywt.gapi.taihe.biz.SubmitScreeningTableRequest request){
            throw unimplementedMethodException(submitScreeningTableMethod);
        }

        @Override
        public com.ywt.gapi.taihe.biz.GetAvailableBookNumResponse getAvailableBookNum(com.ywt.gapi.taihe.biz.GetAvailableBookNumRequest request){
            throw unimplementedMethodException(getAvailableBookNumMethod);
        }





        @Override
        public final ServiceDescriptor getServiceDescriptor() {
            return serviceDescriptor;
        }
        private RpcException unimplementedMethodException(StubMethodDescriptor methodDescriptor) {
            return TriRpcStatus.UNIMPLEMENTED.withDescription(String.format("Method %s is unimplemented",
                "/" + serviceDescriptor.getInterfaceName() + "/" + methodDescriptor.getMethodName())).asException();
        }
    }

}
