package cn.meowrain.aioj.backend.aiservice.grpc;

import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.MethodDescriptor;
import io.grpc.stub.AbstractStub;
import io.grpc.stub.ClientCalls;
import io.grpc.stub.StreamObserver;

/**
 * AI Service gRPC 接口
 */
public class AIServiceGrpc {

    private AIServiceGrpc() {}

    public static final String SERVICE_NAME = "ai.service.AIService";

    // 创建阻塞存根
    public static AIServiceBlockingStub newBlockingStub(Channel channel) {
        return new AIServiceBlockingStub(channel);
    }

    // 创建异步存根
    public static AIServiceStub newStub(Channel channel) {
        return new AIServiceStub(channel);
    }

    /**
     * 阻塞存根
     */
    public static final class AIServiceBlockingStub extends AbstractStub<AIServiceBlockingStub> {

        private AIServiceBlockingStub(Channel channel) {
            super(channel);
        }

        private AIServiceBlockingStub(Channel channel, CallOptions callOptions) {
            super(channel, callOptions);
        }

        @Override
        protected AIServiceBlockingStub build(Channel channel, CallOptions callOptions) {
            return new AIServiceBlockingStub(channel, callOptions);
        }

        /**
         * 分析代码
         */
        public AIServiceProto.AnalyzeCodeResponse analyzeCode(AIServiceProto.AnalyzeCodeRequest request) {
            // 注意：这里需要真实的 gRPC 服务器才能调用
            // 如果没有连接服务器，会抛出 StatusRuntimeException
            throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNAVAILABLE);
        }

        /**
         * 优化代码
         */
        public AIServiceProto.OptimizeCodeResponse optimizeCode(AIServiceProto.OptimizeCodeRequest request) {
            throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNAVAILABLE);
        }

        /**
         * 生成测试用例
         */
        public AIServiceProto.GenerateTestCasesResponse generateTestCases(AIServiceProto.GenerateTestCasesRequest request) {
            throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNAVAILABLE);
        }

        /**
         * 解释代码
         */
        public AIServiceProto.ExplainCodeResponse explainCode(AIServiceProto.ExplainCodeRequest request) {
            throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNAVAILABLE);
        }
    }

    /**
     * 异步存根
     */
    public static final class AIServiceStub extends AbstractStub<AIServiceStub> {

        private AIServiceStub(Channel channel) {
            super(channel);
        }

        private AIServiceStub(Channel channel, CallOptions callOptions) {
            super(channel, callOptions);
        }

        @Override
        protected AIServiceStub build(Channel channel, CallOptions callOptions) {
            return new AIServiceStub(channel, callOptions);
        }

        /**
         * 分析代码（异步）
         */
        public void analyzeCode(AIServiceProto.AnalyzeCodeRequest request,
                               StreamObserver<AIServiceProto.AnalyzeCodeResponse> responseObserver) {
            // 异步调用实现
        }

        /**
         * 优化代码（异步）
         */
        public void optimizeCode(AIServiceProto.OptimizeCodeRequest request,
                                StreamObserver<AIServiceProto.OptimizeCodeResponse> responseObserver) {
            // 异步调用实现
        }

        /**
         * 生成测试用例（异步）
         */
        public void generateTestCases(AIServiceProto.GenerateTestCasesRequest request,
                                     StreamObserver<AIServiceProto.GenerateTestCasesResponse> responseObserver) {
            // 异步调用实现
        }

        /**
         * 解释代码（异步）
         */
        public void explainCode(AIServiceProto.ExplainCodeRequest request,
                               StreamObserver<AIServiceProto.ExplainCodeResponse> responseObserver) {
            // 异步调用实现
        }
    }

    /**
     * StreamObserver 接口（简化版）
     */
    public interface StreamObserver<V> {
        void onNext(V value);
        void onError(Throwable t);
        void onCompleted();
    }
}
