//
// DO NOT EDIT.
//
// Generated by the protocol buffer compiler.
// Source: speechly/sal/v1/evaluator_api.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


/// Service that implements Speechly SAL Evaluation service.
///
/// The service requires a Speechly API token, which is obtained from Speechly Dashboard (https://speechly.com/dashboard).
///
/// The token acts as a proxy for the user who has generated it,
/// i.e. all operations are performed with that user as a subject.
///
/// Usage: instantiate `Speechly_Sal_V1_EvaluatorAPIClient`, then call methods of this protocol to make API calls.
public protocol Speechly_Sal_V1_EvaluatorAPIClientProtocol: GRPCClient {
  var serviceName: String { get }
  var interceptors: Speechly_Sal_V1_EvaluatorAPIClientInterceptorFactoryProtocol? { get }

  func texts(
    _ request: Speechly_Sal_V1_TextsRequest,
    callOptions: CallOptions?
  ) -> UnaryCall<Speechly_Sal_V1_TextsRequest, Speechly_Sal_V1_TextsResponse>

  func evalTexts(
    _ request: Speechly_Sal_V1_EvalTextsRequest,
    callOptions: CallOptions?
  ) -> UnaryCall<Speechly_Sal_V1_EvalTextsRequest, Speechly_Sal_V1_EvalTextsResponse>
}

extension Speechly_Sal_V1_EvaluatorAPIClientProtocol {
  public var serviceName: String {
    return "speechly.sal.v1.EvaluatorAPI"
  }

  /// Performs recognition of a batch of texts with specified language.
  ///
  /// - Parameters:
  ///   - request: Request to send to Texts.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  public func texts(
    _ request: Speechly_Sal_V1_TextsRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Speechly_Sal_V1_TextsRequest, Speechly_Sal_V1_TextsResponse> {
    return self.makeUnaryCall(
      path: "/speechly.sal.v1.EvaluatorAPI/Texts",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeTextsInterceptors() ?? []
    )
  }

  /// Performs recognition of a batch of texts with specified language
  /// and evaluates it against given ground truth texts.
  ///
  /// - Parameters:
  ///   - request: Request to send to EvalTexts.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  public func evalTexts(
    _ request: Speechly_Sal_V1_EvalTextsRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Speechly_Sal_V1_EvalTextsRequest, Speechly_Sal_V1_EvalTextsResponse> {
    return self.makeUnaryCall(
      path: "/speechly.sal.v1.EvaluatorAPI/EvalTexts",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeEvalTextsInterceptors() ?? []
    )
  }
}

public protocol Speechly_Sal_V1_EvaluatorAPIClientInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when invoking 'texts'.
  func makeTextsInterceptors() -> [ClientInterceptor<Speechly_Sal_V1_TextsRequest, Speechly_Sal_V1_TextsResponse>]

  /// - Returns: Interceptors to use when invoking 'evalTexts'.
  func makeEvalTextsInterceptors() -> [ClientInterceptor<Speechly_Sal_V1_EvalTextsRequest, Speechly_Sal_V1_EvalTextsResponse>]
}

public final class Speechly_Sal_V1_EvaluatorAPIClient: Speechly_Sal_V1_EvaluatorAPIClientProtocol {
  public let channel: GRPCChannel
  public var defaultCallOptions: CallOptions
  public var interceptors: Speechly_Sal_V1_EvaluatorAPIClientInterceptorFactoryProtocol?

  /// Creates a client for the speechly.sal.v1.EvaluatorAPI service.
  ///
  /// - Parameters:
  ///   - channel: `GRPCChannel` to the service host.
  ///   - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  ///   - interceptors: A factory providing interceptors for each RPC.
  public init(
    channel: GRPCChannel,
    defaultCallOptions: CallOptions = CallOptions(),
    interceptors: Speechly_Sal_V1_EvaluatorAPIClientInterceptorFactoryProtocol? = nil
  ) {
    self.channel = channel
    self.defaultCallOptions = defaultCallOptions
    self.interceptors = interceptors
  }
}

/// Service that implements Speechly SAL Evaluation service.
///
/// The service requires a Speechly API token, which is obtained from Speechly Dashboard (https://speechly.com/dashboard).
///
/// The token acts as a proxy for the user who has generated it,
/// i.e. all operations are performed with that user as a subject.
///
/// To build a server, implement a class that conforms to this protocol.
public protocol Speechly_Sal_V1_EvaluatorAPIProvider: CallHandlerProvider {
  var interceptors: Speechly_Sal_V1_EvaluatorAPIServerInterceptorFactoryProtocol? { get }

  /// Performs recognition of a batch of texts with specified language.
  func texts(request: Speechly_Sal_V1_TextsRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Speechly_Sal_V1_TextsResponse>

  /// Performs recognition of a batch of texts with specified language
  /// and evaluates it against given ground truth texts.
  func evalTexts(request: Speechly_Sal_V1_EvalTextsRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Speechly_Sal_V1_EvalTextsResponse>
}

extension Speechly_Sal_V1_EvaluatorAPIProvider {
  public var serviceName: Substring { return "speechly.sal.v1.EvaluatorAPI" }

  /// 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 handle(
    method name: Substring,
    context: CallHandlerContext
  ) -> GRPCServerHandlerProtocol? {
    switch name {
    case "Texts":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Speechly_Sal_V1_TextsRequest>(),
        responseSerializer: ProtobufSerializer<Speechly_Sal_V1_TextsResponse>(),
        interceptors: self.interceptors?.makeTextsInterceptors() ?? [],
        userFunction: self.texts(request:context:)
      )

    case "EvalTexts":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Speechly_Sal_V1_EvalTextsRequest>(),
        responseSerializer: ProtobufSerializer<Speechly_Sal_V1_EvalTextsResponse>(),
        interceptors: self.interceptors?.makeEvalTextsInterceptors() ?? [],
        userFunction: self.evalTexts(request:context:)
      )

    default:
      return nil
    }
  }
}

public protocol Speechly_Sal_V1_EvaluatorAPIServerInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when handling 'texts'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeTextsInterceptors() -> [ServerInterceptor<Speechly_Sal_V1_TextsRequest, Speechly_Sal_V1_TextsResponse>]

  /// - Returns: Interceptors to use when handling 'evalTexts'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeEvalTextsInterceptors() -> [ServerInterceptor<Speechly_Sal_V1_EvalTextsRequest, Speechly_Sal_V1_EvalTextsResponse>]
}
