//
// DO NOT EDIT.
//
// Generated by the protocol buffer compiler.
// Source: read_event.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 `Bookowl_ReadEventClient`, then call methods of this protocol to make API calls.
internal protocol Bookowl_ReadEventClientProtocol: GRPCClient {
  var serviceName: String { get }
  var interceptors: Bookowl_ReadEventClientInterceptorFactoryProtocol? { get }

  func createReadEvent(
    _ request: Bookowl_CreateReadEventRequest,
    callOptions: CallOptions?
  ) -> UnaryCall<Bookowl_CreateReadEventRequest, Bookowl_CreateReadEventResponse>

  func getReadEventsByBookID(
    _ request: Bookowl_GetReadEventsByBookIDRequest,
    callOptions: CallOptions?
  ) -> UnaryCall<Bookowl_GetReadEventsByBookIDRequest, Bookowl_GetReadEventsResponse>
}

extension Bookowl_ReadEventClientProtocol {
  internal var serviceName: String {
    return "bookowl.ReadEvent"
  }

  /// Unary call to CreateReadEvent
  ///
  /// - Parameters:
  ///   - request: Request to send to CreateReadEvent.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  internal func createReadEvent(
    _ request: Bookowl_CreateReadEventRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Bookowl_CreateReadEventRequest, Bookowl_CreateReadEventResponse> {
    return self.makeUnaryCall(
      path: "/bookowl.ReadEvent/CreateReadEvent",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeCreateReadEventInterceptors() ?? []
    )
  }

  /// Unary call to GetReadEventsByBookID
  ///
  /// - Parameters:
  ///   - request: Request to send to GetReadEventsByBookID.
  ///   - callOptions: Call options.
  /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  internal func getReadEventsByBookID(
    _ request: Bookowl_GetReadEventsByBookIDRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Bookowl_GetReadEventsByBookIDRequest, Bookowl_GetReadEventsResponse> {
    return self.makeUnaryCall(
      path: "/bookowl.ReadEvent/GetReadEventsByBookID",
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeGetReadEventsByBookIDInterceptors() ?? []
    )
  }
}

internal protocol Bookowl_ReadEventClientInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when invoking 'createReadEvent'.
  func makeCreateReadEventInterceptors() -> [ClientInterceptor<Bookowl_CreateReadEventRequest, Bookowl_CreateReadEventResponse>]

  /// - Returns: Interceptors to use when invoking 'getReadEventsByBookID'.
  func makeGetReadEventsByBookIDInterceptors() -> [ClientInterceptor<Bookowl_GetReadEventsByBookIDRequest, Bookowl_GetReadEventsResponse>]
}

internal final class Bookowl_ReadEventClient: Bookowl_ReadEventClientProtocol {
  internal let channel: GRPCChannel
  internal var defaultCallOptions: CallOptions
  internal var interceptors: Bookowl_ReadEventClientInterceptorFactoryProtocol?

  /// Creates a client for the bookowl.ReadEvent 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: Bookowl_ReadEventClientInterceptorFactoryProtocol? = nil
  ) {
    self.channel = channel
    self.defaultCallOptions = defaultCallOptions
    self.interceptors = interceptors
  }
}

/// To build a server, implement a class that conforms to this protocol.
internal protocol Bookowl_ReadEventProvider: CallHandlerProvider {
  var interceptors: Bookowl_ReadEventServerInterceptorFactoryProtocol? { get }

  func createReadEvent(request: Bookowl_CreateReadEventRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Bookowl_CreateReadEventResponse>

  func getReadEventsByBookID(request: Bookowl_GetReadEventsByBookIDRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Bookowl_GetReadEventsResponse>
}

extension Bookowl_ReadEventProvider {
  internal var serviceName: Substring { return "bookowl.ReadEvent" }

  /// 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 "CreateReadEvent":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Bookowl_CreateReadEventRequest>(),
        responseSerializer: ProtobufSerializer<Bookowl_CreateReadEventResponse>(),
        interceptors: self.interceptors?.makeCreateReadEventInterceptors() ?? [],
        userFunction: self.createReadEvent(request:context:)
      )

    case "GetReadEventsByBookID":
      return UnaryServerHandler(
        context: context,
        requestDeserializer: ProtobufDeserializer<Bookowl_GetReadEventsByBookIDRequest>(),
        responseSerializer: ProtobufSerializer<Bookowl_GetReadEventsResponse>(),
        interceptors: self.interceptors?.makeGetReadEventsByBookIDInterceptors() ?? [],
        userFunction: self.getReadEventsByBookID(request:context:)
      )

    default:
      return nil
    }
  }
}

internal protocol Bookowl_ReadEventServerInterceptorFactoryProtocol {

  /// - Returns: Interceptors to use when handling 'createReadEvent'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeCreateReadEventInterceptors() -> [ServerInterceptor<Bookowl_CreateReadEventRequest, Bookowl_CreateReadEventResponse>]

  /// - Returns: Interceptors to use when handling 'getReadEventsByBookID'.
  ///   Defaults to calling `self.makeInterceptors()`.
  func makeGetReadEventsByBookIDInterceptors() -> [ServerInterceptor<Bookowl_GetReadEventsByBookIDRequest, Bookowl_GetReadEventsResponse>]
}
