/*
* 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.third.cloudfilm;

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 DubboCloudfilm2DServiceTriple {

    public static final String SERVICE_NAME = Cloudfilm2DService.SERVICE_NAME;

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

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

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

    /**
         * <pre>
         * 医院Id（太和医院为12）
         * </pre>
         */
    private static final StubMethodDescriptor get2DCloudfilmUrlMethod = new StubMethodDescriptor("get2DCloudfilmUrl",
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest.class, com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest::parseFrom,
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse::parseFrom);

    private static final StubMethodDescriptor get2DCloudfilmUrlAsyncMethod = new StubMethodDescriptor("get2DCloudfilmUrl",
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest::parseFrom,
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse::parseFrom);

    private static final StubMethodDescriptor get2DCloudfilmUrlProxyAsyncMethod = new StubMethodDescriptor("get2DCloudfilmUrlAsync",
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest.class, com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest::parseFrom,
    com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse::parseFrom);





    public static class Cloudfilm2DServiceStub implements Cloudfilm2DService{
        private final Invoker<Cloudfilm2DService> invoker;

        public Cloudfilm2DServiceStub(Invoker<Cloudfilm2DService> invoker) {
            this.invoker = invoker;
        }

            /**
         * <pre>
         * 医院Id（太和医院为12）
         * </pre>
         */
        @Override
        public com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse get2DCloudfilmUrl(com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest request){
            return StubInvocationUtil.unaryCall(invoker, get2DCloudfilmUrlMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse> get2DCloudfilmUrlAsync(com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest request){
            return StubInvocationUtil.unaryCall(invoker, get2DCloudfilmUrlAsyncMethod, request);
        }

            /**
         * <pre>
         * 医院Id（太和医院为12）
         * </pre>
         */
        @Override
        public void get2DCloudfilmUrl(com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest request, StreamObserver<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, get2DCloudfilmUrlMethod , request, responseObserver);
        }



    }

    public static abstract class Cloudfilm2DServiceImplBase implements Cloudfilm2DService, ServerService<Cloudfilm2DService> {

        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<Cloudfilm2DService> getInvoker(URL url) {
            PathResolver pathResolver = url.getOrDefaultFrameworkModel()
            .getExtensionLoader(PathResolver.class)
            .getDefaultExtension();
            Map<String,StubMethodHandler<?, ?>> handlers = new HashMap<>();

            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/get2DCloudfilmUrl" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/get2DCloudfilmUrlAsync" );

            BiConsumer<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest, StreamObserver<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse>> get2DCloudfilmUrlFunc = this::get2DCloudfilmUrl;
            handlers.put(get2DCloudfilmUrlMethod.getMethodName(), new UnaryStubMethodHandler<>(get2DCloudfilmUrlFunc));
            BiConsumer<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest, StreamObserver<com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse>> get2DCloudfilmUrlAsyncFunc = syncToAsync(this::get2DCloudfilmUrl);
            handlers.put(get2DCloudfilmUrlProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(get2DCloudfilmUrlAsyncFunc));




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


        @Override
        public com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlResponse get2DCloudfilmUrl(com.ywt.gapi.third.cloudfilm.Get2DCloudfilmUrlRequest request){
            throw unimplementedMethodException(get2DCloudfilmUrlMethod);
        }





        @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();
        }
    }

}
