//
// DO NOT EDIT.
//
// Generated by the protocol buffer compiler.
// Source: worker_service.proto
//

//
// Copyright 2018, gRPC Authors All rights reserved.
//
// Licensed 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.
//
import GRPC
import NIO
import SwiftProtobuf


/// Usage: instantiate Grpc_Testing_WorkerServiceClient, then call methods of this protocol to make API calls.
public protocol Grpc_Testing_WorkerServiceClientProtocol: GRPCClient {
  func runServer(
    callOptions: CallOptions?,
    handler: @escaping (Grpc_Testing_ServerStatus) -> Void
  ) -> BidirectionalStreamingCall<Grpc_Testing_ServerArgs, Grpc_Testing_ServerStatus>

  func runClient(
    callOptions: CallOptions?,
    handler: @escaping (Grpc_Testing_ClientStatus) -> Void
  ) -> BidirectionalStreamingCall<Grpc_Testing_ClientArgs, Grpc_Testing_ClientStatus>

  func coreCount(
    _ request: Grpc_Testing_CoreRequest,
    callOptions: CallOptions?
  ) -> UnaryCall<Grpc_Testing_CoreRequest, Grpc_Testing_CoreResponse>

  func quitWorker(
    _ request: Grpc_Testing_Void,
    callOptions: CallOptions?
  ) -> UnaryCall<Grpc_Testing_Void, Grpc_Testing_Void>

}

extension Grpc_Testing_WorkerServiceClientProtocol {

  /// Start server with specified workload.
  /// First request sent specifies the ServerConfig followed by ServerStatus
  /// response. After that, a "Mark" can be sent anytime to request the latest
  /// stats. Closing the stream will initiate shutdown of the test server
  /// and once the shutdown has finished, the OK status is sent to terminate
  /// this RPC.
  ///
  /// Callers should use the `send` method on the returned object to send messages
  /// to the server. The caller should send an `.end` after the final message has been sent.
  ///
  /// - Parameters:
  ///   - callOptions: Call options.
  ///   - handler: A closure called when each response is received from the server.
  /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  public func runServer(
    callOptions: CallOptions? = nil,
    handler: @escaping (Grpc_Testing_ServerStatus) -> Void
  ) -> BidirectionalStreamingCall<Grpc_Testing_ServerArgs, Grpc_Testing_ServerStatus> {
    return self.makeBidirectionalStreamingCall(
      path: "/grpc.testing.WorkerService/RunServer",
      callOptions: callOptions ?? self.defaultCallOptions,
      handler: handler
    )
  }

  /// Start client with specified workload.
  /// First request sent specifies the ClientConfig followed by ClientStatus
  /// response. After that, a "Mark" can be sent anytime to request the latest
  /// stats. Closing the stream will initiate shutdown of the test client
  /// and once the shutdown has finished, the OK status is sent to terminate
  /// this RPC.
  ///
  /// Callers should use the `send` method on the returned object to send messages
  /// to the server. The caller should send an `.end` after the final message has been sent.
  ///
  /// - Parameters:
  ///   - callOptions: Call options.
  ///   - handler: A closure called when each response is received from the server.
  /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  public func runClient(
    callOptions: CallOptions? = nil,
    handler: @escaping (Grpc_Testing_ClientStatus) -> Void
  ) -> BidirectionalStreamingCall<Grpc_Testing_ClientArgs, Grpc_Testing_ClientStatus> {
    return self.makeBidirectionalStreamingCall(
      path: "/grpc.testing.WorkerService/RunClient",
      callOptions: callOptions ?? self.defaultCallOptions,
      handler: handler
    )
  }

  /// Just return the core count - unary call
  ///
  /// - Parameters:
  ///   - request: Request to send to CoreCount.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  public func coreCount(
    _ request: Grpc_Testing_CoreRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Grpc_Testing_CoreRequest, Grpc_Testing_CoreResponse> {
    return self.makeUnaryCall(
      path: "/grpc.testing.WorkerService/CoreCount",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions
    )
  }

  /// Quit this worker
  ///
  /// - Parameters:
  ///   - request: Request to send to QuitWorker.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  public func quitWorker(
    _ request: Grpc_Testing_Void,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Grpc_Testing_Void, Grpc_Testing_Void> {
    return self.makeUnaryCall(
      path: "/grpc.testing.WorkerService/QuitWorker",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions
    )
  }
}

public final class Grpc_Testing_WorkerServiceClient: Grpc_Testing_WorkerServiceClientProtocol {
  public let channel: GRPCChannel
  public var defaultCallOptions: CallOptions

  /// Creates a client for the grpc.testing.WorkerService service.
  ///
  /// - Parameters:
  ///   - channel: `GRPCChannel` to the service host.
  ///   - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
    self.channel = channel
    self.defaultCallOptions = defaultCallOptions
  }
}

/// To build a server, implement a class that conforms to this protocol.
public protocol Grpc_Testing_WorkerServiceProvider: CallHandlerProvider {
  /// Start server with specified workload.
  /// First request sent specifies the ServerConfig followed by ServerStatus
  /// response. After that, a "Mark" can be sent anytime to request the latest
  /// stats. Closing the stream will initiate shutdown of the test server
  /// and once the shutdown has finished, the OK status is sent to terminate
  /// this RPC.
  func runServer(context: StreamingResponseCallContext<Grpc_Testing_ServerStatus>) -> EventLoopFuture<(StreamEvent<Grpc_Testing_ServerArgs>) -> Void>
  /// Start client with specified workload.
  /// First request sent specifies the ClientConfig followed by ClientStatus
  /// response. After that, a "Mark" can be sent anytime to request the latest
  /// stats. Closing the stream will initiate shutdown of the test client
  /// and once the shutdown has finished, the OK status is sent to terminate
  /// this RPC.
  func runClient(context: StreamingResponseCallContext<Grpc_Testing_ClientStatus>) -> EventLoopFuture<(StreamEvent<Grpc_Testing_ClientArgs>) -> Void>
  /// Just return the core count - unary call
  func coreCount(request: Grpc_Testing_CoreRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Grpc_Testing_CoreResponse>
  /// Quit this worker
  func quitWorker(request: Grpc_Testing_Void, context: StatusOnlyCallContext) -> EventLoopFuture<Grpc_Testing_Void>
}

extension Grpc_Testing_WorkerServiceProvider {
  public var serviceName: Substring { return "grpc.testing.WorkerService" }

  /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  /// Returns nil for methods not handled by this service.
  public func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
    switch methodName {
    case "RunServer":
      return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in
        return self.runServer(context: context)
      }

    case "RunClient":
      return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in
        return self.runClient(context: context)
      }

    case "CoreCount":
      return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
        return { request in
          self.coreCount(request: request, context: context)
        }
      }

    case "QuitWorker":
      return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
        return { request in
          self.quitWorker(request: request, context: context)
        }
      }

    default: return nil
    }
  }
}

