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

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

    public static final String SERVICE_NAME = SFInternalService.SERVICE_NAME;

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

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

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

    /**
         * <pre>
         * [R]订单编号
         * </pre>
         */
    private static final StubMethodDescriptor getCityCodeMethod = new StubMethodDescriptor("getCityCode",
    com.ywt.gapi.sf.GetCityCodeRequest.class, com.ywt.gapi.sf.GetCityCodeResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetCityCodeRequest::parseFrom,
    com.ywt.gapi.sf.GetCityCodeResponse::parseFrom);

    private static final StubMethodDescriptor getCityCodeAsyncMethod = new StubMethodDescriptor("getCityCode",
    com.ywt.gapi.sf.GetCityCodeRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetCityCodeRequest::parseFrom,
    com.ywt.gapi.sf.GetCityCodeResponse::parseFrom);

    private static final StubMethodDescriptor getCityCodeProxyAsyncMethod = new StubMethodDescriptor("getCityCodeAsync",
    com.ywt.gapi.sf.GetCityCodeRequest.class, com.ywt.gapi.sf.GetCityCodeResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetCityCodeRequest::parseFrom,
    com.ywt.gapi.sf.GetCityCodeResponse::parseFrom);

    /**
         * <pre>
         * [O]快件产品类型。1-标准快递；2-顺丰特惠；3-电商特惠；6-即日件，12-医药专递等。详情查阅顺丰规范文档
         * </pre>
         */
    private static final StubMethodDescriptor saveRouteInfoMethod = new StubMethodDescriptor("saveRouteInfo",
    com.ywt.gapi.sf.SaveRouteInfoRequest.class, com.ywt.gapi.sf.BaseResultResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.SaveRouteInfoRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);

    private static final StubMethodDescriptor saveRouteInfoAsyncMethod = new StubMethodDescriptor("saveRouteInfo",
    com.ywt.gapi.sf.SaveRouteInfoRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.SaveRouteInfoRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);

    private static final StubMethodDescriptor saveRouteInfoProxyAsyncMethod = new StubMethodDescriptor("saveRouteInfoAsync",
    com.ywt.gapi.sf.SaveRouteInfoRequest.class, com.ywt.gapi.sf.BaseResultResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.SaveRouteInfoRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);

    /**
         * <pre>
         * [C]寄件方地址，必须包含省市区.如果需要生成电子运单，则为必填。
         * </pre>
         */
    private static final StubMethodDescriptor getRouteListMethod = new StubMethodDescriptor("getRouteList",
    com.ywt.gapi.sf.GetRouteListRequest.class, com.ywt.gapi.sf.GetRouteResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetRouteListRequest::parseFrom,
    com.ywt.gapi.sf.GetRouteResponse::parseFrom);

    private static final StubMethodDescriptor getRouteListAsyncMethod = new StubMethodDescriptor("getRouteList",
    com.ywt.gapi.sf.GetRouteListRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetRouteListRequest::parseFrom,
    com.ywt.gapi.sf.GetRouteResponse::parseFrom);

    private static final StubMethodDescriptor getRouteListProxyAsyncMethod = new StubMethodDescriptor("getRouteListAsync",
    com.ywt.gapi.sf.GetRouteListRequest.class, com.ywt.gapi.sf.GetRouteResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.GetRouteListRequest::parseFrom,
    com.ywt.gapi.sf.GetRouteResponse::parseFrom);

    /**
         * <pre>
         * [R[寄件方公司
         * </pre>
         */
    private static final StubMethodDescriptor updatePrescriptionStatusMethod = new StubMethodDescriptor("updatePrescriptionStatus",
    com.ywt.gapi.sf.UpdatePrescriptionStatusRequest.class, com.ywt.gapi.sf.BaseResultResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.UpdatePrescriptionStatusRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);

    private static final StubMethodDescriptor updatePrescriptionStatusAsyncMethod = new StubMethodDescriptor("updatePrescriptionStatus",
    com.ywt.gapi.sf.UpdatePrescriptionStatusRequest.class, java.util.concurrent.CompletableFuture.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.UpdatePrescriptionStatusRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);

    private static final StubMethodDescriptor updatePrescriptionStatusProxyAsyncMethod = new StubMethodDescriptor("updatePrescriptionStatusAsync",
    com.ywt.gapi.sf.UpdatePrescriptionStatusRequest.class, com.ywt.gapi.sf.BaseResultResponse.class, serviceDescriptor, MethodDescriptor.RpcType.UNARY,
    obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), com.ywt.gapi.sf.UpdatePrescriptionStatusRequest::parseFrom,
    com.ywt.gapi.sf.BaseResultResponse::parseFrom);





    public static class SFInternalServiceStub implements SFInternalService{
        private final Invoker<SFInternalService> invoker;

        public SFInternalServiceStub(Invoker<SFInternalService> invoker) {
            this.invoker = invoker;
        }

            /**
         * <pre>
         * [R]订单编号
         * </pre>
         */
        @Override
        public com.ywt.gapi.sf.GetCityCodeResponse getCityCode(com.ywt.gapi.sf.GetCityCodeRequest request){
            return StubInvocationUtil.unaryCall(invoker, getCityCodeMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.sf.GetCityCodeResponse> getCityCodeAsync(com.ywt.gapi.sf.GetCityCodeRequest request){
            return StubInvocationUtil.unaryCall(invoker, getCityCodeAsyncMethod, request);
        }

            /**
         * <pre>
         * [R]订单编号
         * </pre>
         */
        @Override
        public void getCityCode(com.ywt.gapi.sf.GetCityCodeRequest request, StreamObserver<com.ywt.gapi.sf.GetCityCodeResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, getCityCodeMethod , request, responseObserver);
        }
            /**
         * <pre>
         * [O]快件产品类型。1-标准快递；2-顺丰特惠；3-电商特惠；6-即日件，12-医药专递等。详情查阅顺丰规范文档
         * </pre>
         */
        @Override
        public com.ywt.gapi.sf.BaseResultResponse saveRouteInfo(com.ywt.gapi.sf.SaveRouteInfoRequest request){
            return StubInvocationUtil.unaryCall(invoker, saveRouteInfoMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.sf.BaseResultResponse> saveRouteInfoAsync(com.ywt.gapi.sf.SaveRouteInfoRequest request){
            return StubInvocationUtil.unaryCall(invoker, saveRouteInfoAsyncMethod, request);
        }

            /**
         * <pre>
         * [O]快件产品类型。1-标准快递；2-顺丰特惠；3-电商特惠；6-即日件，12-医药专递等。详情查阅顺丰规范文档
         * </pre>
         */
        @Override
        public void saveRouteInfo(com.ywt.gapi.sf.SaveRouteInfoRequest request, StreamObserver<com.ywt.gapi.sf.BaseResultResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, saveRouteInfoMethod , request, responseObserver);
        }
            /**
         * <pre>
         * [C]寄件方地址，必须包含省市区.如果需要生成电子运单，则为必填。
         * </pre>
         */
        @Override
        public com.ywt.gapi.sf.GetRouteResponse getRouteList(com.ywt.gapi.sf.GetRouteListRequest request){
            return StubInvocationUtil.unaryCall(invoker, getRouteListMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.sf.GetRouteResponse> getRouteListAsync(com.ywt.gapi.sf.GetRouteListRequest request){
            return StubInvocationUtil.unaryCall(invoker, getRouteListAsyncMethod, request);
        }

            /**
         * <pre>
         * [C]寄件方地址，必须包含省市区.如果需要生成电子运单，则为必填。
         * </pre>
         */
        @Override
        public void getRouteList(com.ywt.gapi.sf.GetRouteListRequest request, StreamObserver<com.ywt.gapi.sf.GetRouteResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, getRouteListMethod , request, responseObserver);
        }
            /**
         * <pre>
         * [R[寄件方公司
         * </pre>
         */
        @Override
        public com.ywt.gapi.sf.BaseResultResponse updatePrescriptionStatus(com.ywt.gapi.sf.UpdatePrescriptionStatusRequest request){
            return StubInvocationUtil.unaryCall(invoker, updatePrescriptionStatusMethod, request);
        }

        public CompletableFuture<com.ywt.gapi.sf.BaseResultResponse> updatePrescriptionStatusAsync(com.ywt.gapi.sf.UpdatePrescriptionStatusRequest request){
            return StubInvocationUtil.unaryCall(invoker, updatePrescriptionStatusAsyncMethod, request);
        }

            /**
         * <pre>
         * [R[寄件方公司
         * </pre>
         */
        @Override
        public void updatePrescriptionStatus(com.ywt.gapi.sf.UpdatePrescriptionStatusRequest request, StreamObserver<com.ywt.gapi.sf.BaseResultResponse> responseObserver){
            StubInvocationUtil.unaryCall(invoker, updatePrescriptionStatusMethod , request, responseObserver);
        }



    }

    public static abstract class SFInternalServiceImplBase implements SFInternalService, ServerService<SFInternalService> {

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

            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getCityCode" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getCityCodeAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/saveRouteInfo" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/saveRouteInfoAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getRouteList" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/getRouteListAsync" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/updatePrescriptionStatus" );
            pathResolver.addNativeStub( "/" + SERVICE_NAME + "/updatePrescriptionStatusAsync" );

            BiConsumer<com.ywt.gapi.sf.GetCityCodeRequest, StreamObserver<com.ywt.gapi.sf.GetCityCodeResponse>> getCityCodeFunc = this::getCityCode;
            handlers.put(getCityCodeMethod.getMethodName(), new UnaryStubMethodHandler<>(getCityCodeFunc));
            BiConsumer<com.ywt.gapi.sf.GetCityCodeRequest, StreamObserver<com.ywt.gapi.sf.GetCityCodeResponse>> getCityCodeAsyncFunc = syncToAsync(this::getCityCode);
            handlers.put(getCityCodeProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getCityCodeAsyncFunc));
            BiConsumer<com.ywt.gapi.sf.SaveRouteInfoRequest, StreamObserver<com.ywt.gapi.sf.BaseResultResponse>> saveRouteInfoFunc = this::saveRouteInfo;
            handlers.put(saveRouteInfoMethod.getMethodName(), new UnaryStubMethodHandler<>(saveRouteInfoFunc));
            BiConsumer<com.ywt.gapi.sf.SaveRouteInfoRequest, StreamObserver<com.ywt.gapi.sf.BaseResultResponse>> saveRouteInfoAsyncFunc = syncToAsync(this::saveRouteInfo);
            handlers.put(saveRouteInfoProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(saveRouteInfoAsyncFunc));
            BiConsumer<com.ywt.gapi.sf.GetRouteListRequest, StreamObserver<com.ywt.gapi.sf.GetRouteResponse>> getRouteListFunc = this::getRouteList;
            handlers.put(getRouteListMethod.getMethodName(), new UnaryStubMethodHandler<>(getRouteListFunc));
            BiConsumer<com.ywt.gapi.sf.GetRouteListRequest, StreamObserver<com.ywt.gapi.sf.GetRouteResponse>> getRouteListAsyncFunc = syncToAsync(this::getRouteList);
            handlers.put(getRouteListProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getRouteListAsyncFunc));
            BiConsumer<com.ywt.gapi.sf.UpdatePrescriptionStatusRequest, StreamObserver<com.ywt.gapi.sf.BaseResultResponse>> updatePrescriptionStatusFunc = this::updatePrescriptionStatus;
            handlers.put(updatePrescriptionStatusMethod.getMethodName(), new UnaryStubMethodHandler<>(updatePrescriptionStatusFunc));
            BiConsumer<com.ywt.gapi.sf.UpdatePrescriptionStatusRequest, StreamObserver<com.ywt.gapi.sf.BaseResultResponse>> updatePrescriptionStatusAsyncFunc = syncToAsync(this::updatePrescriptionStatus);
            handlers.put(updatePrescriptionStatusProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(updatePrescriptionStatusAsyncFunc));




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


        @Override
        public com.ywt.gapi.sf.GetCityCodeResponse getCityCode(com.ywt.gapi.sf.GetCityCodeRequest request){
            throw unimplementedMethodException(getCityCodeMethod);
        }

        @Override
        public com.ywt.gapi.sf.BaseResultResponse saveRouteInfo(com.ywt.gapi.sf.SaveRouteInfoRequest request){
            throw unimplementedMethodException(saveRouteInfoMethod);
        }

        @Override
        public com.ywt.gapi.sf.GetRouteResponse getRouteList(com.ywt.gapi.sf.GetRouteListRequest request){
            throw unimplementedMethodException(getRouteListMethod);
        }

        @Override
        public com.ywt.gapi.sf.BaseResultResponse updatePrescriptionStatus(com.ywt.gapi.sf.UpdatePrescriptionStatusRequest request){
            throw unimplementedMethodException(updatePrescriptionStatusMethod);
        }





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

}
