//
// DO NOT EDIT.
//
// Generated by the protocol buffer compiler.
// Source: iris_mod/htlc/tx.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


/// Msg defines the HTLC Msg service
///
/// Usage: instantiate `Irismod_Htlc_MsgClient`, then call methods of this protocol to make API calls.
internal protocol Irismod_Htlc_MsgClientProtocol: GRPCClient {
  var serviceName: String { get }
  var interceptors: Irismod_Htlc_MsgClientInterceptorFactoryProtocol? { get }

  func createHTLC(
    _ request: Irismod_Htlc_MsgCreateHTLC,
    callOptions: CallOptions?
  ) -> UnaryCall<Irismod_Htlc_MsgCreateHTLC, Irismod_Htlc_MsgCreateHTLCResponse>

  func claimHTLC(
    _ request: Irismod_Htlc_MsgClaimHTLC,
    callOptions: CallOptions?
  ) -> UnaryCall<Irismod_Htlc_MsgClaimHTLC, Irismod_Htlc_MsgClaimHTLCResponse>
}

extension Irismod_Htlc_MsgClientProtocol {
  internal var serviceName: String {
    return "irismod.htlc.Msg"
  }

  /// CreateHTLC defines a method for creating a HTLC
  ///
  /// - Parameters:
  ///   - request: Request to send to CreateHTLC.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  internal func createHTLC(
    _ request: Irismod_Htlc_MsgCreateHTLC,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Irismod_Htlc_MsgCreateHTLC, Irismod_Htlc_MsgCreateHTLCResponse> {
    return self.makeUnaryCall(
      path: "/irismod.htlc.Msg/CreateHTLC",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeCreateHTLCInterceptors() ?? []
    )
  }

  /// ClaimHTLC defines a method for claiming a HTLC
  ///
  /// - Parameters:
  ///   - request: Request to send to ClaimHTLC.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  internal func claimHTLC(
    _ request: Irismod_Htlc_MsgClaimHTLC,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Irismod_Htlc_MsgClaimHTLC, Irismod_Htlc_MsgClaimHTLCResponse> {
    return self.makeUnaryCall(
      path: "/irismod.htlc.Msg/ClaimHTLC",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeClaimHTLCInterceptors() ?? []
    )
  }
}

internal protocol Irismod_Htlc_MsgClientInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when invoking 'createHTLC'.
  func makeCreateHTLCInterceptors() -> [ClientInterceptor<Irismod_Htlc_MsgCreateHTLC, Irismod_Htlc_MsgCreateHTLCResponse>]

  /// - Returns: Interceptors to use when invoking 'claimHTLC'.
  func makeClaimHTLCInterceptors() -> [ClientInterceptor<Irismod_Htlc_MsgClaimHTLC, Irismod_Htlc_MsgClaimHTLCResponse>]
}

internal final class Irismod_Htlc_MsgClient: Irismod_Htlc_MsgClientProtocol {
  internal let channel: GRPCChannel
  internal var defaultCallOptions: CallOptions
  internal var interceptors: Irismod_Htlc_MsgClientInterceptorFactoryProtocol?

  /// Creates a client for the irismod.htlc.Msg 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.
  internal init(
    channel: GRPCChannel,
    defaultCallOptions: CallOptions = CallOptions(),
    interceptors: Irismod_Htlc_MsgClientInterceptorFactoryProtocol? = nil
  ) {
    self.channel = channel
    self.defaultCallOptions = defaultCallOptions
    self.interceptors = interceptors
  }
}

/// Msg defines the HTLC Msg service
///
/// To build a server, implement a class that conforms to this protocol.
internal protocol Irismod_Htlc_MsgProvider: CallHandlerProvider {
  var interceptors: Irismod_Htlc_MsgServerInterceptorFactoryProtocol? { get }

  /// CreateHTLC defines a method for creating a HTLC
  func createHTLC(request: Irismod_Htlc_MsgCreateHTLC, context: StatusOnlyCallContext) -> EventLoopFuture<Irismod_Htlc_MsgCreateHTLCResponse>

  /// ClaimHTLC defines a method for claiming a HTLC
  func claimHTLC(request: Irismod_Htlc_MsgClaimHTLC, context: StatusOnlyCallContext) -> EventLoopFuture<Irismod_Htlc_MsgClaimHTLCResponse>
}

extension Irismod_Htlc_MsgProvider {
  internal var serviceName: Substring { return "irismod.htlc.Msg" }

  /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  /// Returns nil for methods not handled by this service.
  internal func handle(
    method name: Substring,
    context: CallHandlerContext
  ) -> GRPCServerHandlerProtocol? {
    switch name {
    case "CreateHTLC":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Irismod_Htlc_MsgCreateHTLC>(),
        responseSerializer: ProtobufSerializer<Irismod_Htlc_MsgCreateHTLCResponse>(),
        interceptors: self.interceptors?.makeCreateHTLCInterceptors() ?? [],
        userFunction: self.createHTLC(request:context:)
      )

    case "ClaimHTLC":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Irismod_Htlc_MsgClaimHTLC>(),
        responseSerializer: ProtobufSerializer<Irismod_Htlc_MsgClaimHTLCResponse>(),
        interceptors: self.interceptors?.makeClaimHTLCInterceptors() ?? [],
        userFunction: self.claimHTLC(request:context:)
      )

    default:
      return nil
    }
  }
}

internal protocol Irismod_Htlc_MsgServerInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when handling 'createHTLC'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeCreateHTLCInterceptors() -> [ServerInterceptor<Irismod_Htlc_MsgCreateHTLC, Irismod_Htlc_MsgCreateHTLCResponse>]

  /// - Returns: Interceptors to use when handling 'claimHTLC'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeClaimHTLCInterceptors() -> [ServerInterceptor<Irismod_Htlc_MsgClaimHTLC, Irismod_Htlc_MsgClaimHTLCResponse>]
}
