//
// DO NOT EDIT.
//
// Generated by the protocol buffer compiler.
// Source: 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 Foundation
import Dispatch
import SwiftGRPC
import SwiftProtobuf

internal protocol MemoryIOReadCall: ClientCallUnary {}

fileprivate final class MemoryIOReadCallBase: ClientCallUnaryBase<MemoryReadRequest, MemoryReadResponse>, MemoryIOReadCall {
  override class var method: String { return "/MemoryIO/Read" }
}

internal protocol MemoryIOWriteCall: ClientCallUnary {}

fileprivate final class MemoryIOWriteCallBase: ClientCallUnaryBase<MemoryWriteRequest, MemoryWriteResponse>, MemoryIOWriteCall {
  override class var method: String { return "/MemoryIO/Write" }
}


/// Instantiate MemoryIOServiceClient, then call methods of this protocol to make API calls.
internal protocol MemoryIOService: ServiceClient {
  /// Synchronous. Unary.
  func read(_ request: MemoryReadRequest) throws -> MemoryReadResponse
  /// Asynchronous. Unary.
  func read(_ request: MemoryReadRequest, completion: @escaping (MemoryReadResponse?, CallResult) -> Void) throws -> MemoryIOReadCall

  /// Synchronous. Unary.
  func write(_ request: MemoryWriteRequest) throws -> MemoryWriteResponse
  /// Asynchronous. Unary.
  func write(_ request: MemoryWriteRequest, completion: @escaping (MemoryWriteResponse?, CallResult) -> Void) throws -> MemoryIOWriteCall

}

internal final class MemoryIOServiceClient: ServiceClientBase, MemoryIOService {
  /// Synchronous. Unary.
  internal func read(_ request: MemoryReadRequest) throws -> MemoryReadResponse {
    return try MemoryIOReadCallBase(channel)
      .run(request: request, metadata: metadata)
  }
  /// Asynchronous. Unary.
  internal func read(_ request: MemoryReadRequest, completion: @escaping (MemoryReadResponse?, CallResult) -> Void) throws -> MemoryIOReadCall {
    return try MemoryIOReadCallBase(channel)
      .start(request: request, metadata: metadata, completion: completion)
  }

  /// Synchronous. Unary.
  internal func write(_ request: MemoryWriteRequest) throws -> MemoryWriteResponse {
    return try MemoryIOWriteCallBase(channel)
      .run(request: request, metadata: metadata)
  }
  /// Asynchronous. Unary.
  internal func write(_ request: MemoryWriteRequest, completion: @escaping (MemoryWriteResponse?, CallResult) -> Void) throws -> MemoryIOWriteCall {
    return try MemoryIOWriteCallBase(channel)
      .start(request: request, metadata: metadata, completion: completion)
  }

}
internal protocol KeyboardPressCall: ClientCallUnary {}

fileprivate final class KeyboardPressCallBase: ClientCallUnaryBase<KeyStroke, KeyboardResponse>, KeyboardPressCall {
  override class var method: String { return "/Keyboard/Press" }
}

internal protocol KeyboardReleaseCall: ClientCallUnary {}

fileprivate final class KeyboardReleaseCallBase: ClientCallUnaryBase<KeyStroke, KeyboardResponse>, KeyboardReleaseCall {
  override class var method: String { return "/Keyboard/Release" }
}


/// Instantiate KeyboardServiceClient, then call methods of this protocol to make API calls.
internal protocol KeyboardService: ServiceClient {
  /// Synchronous. Unary.
  func press(_ request: KeyStroke) throws -> KeyboardResponse
  /// Asynchronous. Unary.
  func press(_ request: KeyStroke, completion: @escaping (KeyboardResponse?, CallResult) -> Void) throws -> KeyboardPressCall

  /// Synchronous. Unary.
  func release(_ request: KeyStroke) throws -> KeyboardResponse
  /// Asynchronous. Unary.
  func release(_ request: KeyStroke, completion: @escaping (KeyboardResponse?, CallResult) -> Void) throws -> KeyboardReleaseCall

}

internal final class KeyboardServiceClient: ServiceClientBase, KeyboardService {
  /// Synchronous. Unary.
  internal func press(_ request: KeyStroke) throws -> KeyboardResponse {
    return try KeyboardPressCallBase(channel)
      .run(request: request, metadata: metadata)
  }
  /// Asynchronous. Unary.
  internal func press(_ request: KeyStroke, completion: @escaping (KeyboardResponse?, CallResult) -> Void) throws -> KeyboardPressCall {
    return try KeyboardPressCallBase(channel)
      .start(request: request, metadata: metadata, completion: completion)
  }

  /// Synchronous. Unary.
  internal func release(_ request: KeyStroke) throws -> KeyboardResponse {
    return try KeyboardReleaseCallBase(channel)
      .run(request: request, metadata: metadata)
  }
  /// Asynchronous. Unary.
  internal func release(_ request: KeyStroke, completion: @escaping (KeyboardResponse?, CallResult) -> Void) throws -> KeyboardReleaseCall {
    return try KeyboardReleaseCallBase(channel)
      .start(request: request, metadata: metadata, completion: completion)
  }

}

/// To build a server, implement a class that conforms to this protocol.
/// If one of the methods returning `ServerStatus?` returns nil,
/// it is expected that you have already returned a status to the client by means of `session.close`.
internal protocol MemoryIOProvider: ServiceProvider {
  func read(request: MemoryReadRequest, session: MemoryIOReadSession) throws -> MemoryReadResponse
  func write(request: MemoryWriteRequest, session: MemoryIOWriteSession) throws -> MemoryWriteResponse
}

extension MemoryIOProvider {
  internal var serviceName: String { return "MemoryIO" }

  /// Determines and calls the appropriate request handler, depending on the request's method.
  /// Throws `HandleMethodError.unknownMethod` for methods not handled by this service.
  internal func handleMethod(_ method: String, handler: Handler) throws -> ServerStatus? {
    switch method {
    case "/MemoryIO/Read":
      return try MemoryIOReadSessionBase(
        handler: handler,
        providerBlock: { try self.read(request: $0, session: $1 as! MemoryIOReadSessionBase) })
          .run()
    case "/MemoryIO/Write":
      return try MemoryIOWriteSessionBase(
        handler: handler,
        providerBlock: { try self.write(request: $0, session: $1 as! MemoryIOWriteSessionBase) })
          .run()
    default:
      throw HandleMethodError.unknownMethod
    }
  }
}

internal protocol MemoryIOReadSession: ServerSessionUnary {}

fileprivate final class MemoryIOReadSessionBase: ServerSessionUnaryBase<MemoryReadRequest, MemoryReadResponse>, MemoryIOReadSession {}

internal protocol MemoryIOWriteSession: ServerSessionUnary {}

fileprivate final class MemoryIOWriteSessionBase: ServerSessionUnaryBase<MemoryWriteRequest, MemoryWriteResponse>, MemoryIOWriteSession {}

/// To build a server, implement a class that conforms to this protocol.
/// If one of the methods returning `ServerStatus?` returns nil,
/// it is expected that you have already returned a status to the client by means of `session.close`.
internal protocol KeyboardProvider: ServiceProvider {
  func press(request: KeyStroke, session: KeyboardPressSession) throws -> KeyboardResponse
  func release(request: KeyStroke, session: KeyboardReleaseSession) throws -> KeyboardResponse
}

extension KeyboardProvider {
  internal var serviceName: String { return "Keyboard" }

  /// Determines and calls the appropriate request handler, depending on the request's method.
  /// Throws `HandleMethodError.unknownMethod` for methods not handled by this service.
  internal func handleMethod(_ method: String, handler: Handler) throws -> ServerStatus? {
    switch method {
    case "/Keyboard/Press":
      return try KeyboardPressSessionBase(
        handler: handler,
        providerBlock: { try self.press(request: $0, session: $1 as! KeyboardPressSessionBase) })
          .run()
    case "/Keyboard/Release":
      return try KeyboardReleaseSessionBase(
        handler: handler,
        providerBlock: { try self.release(request: $0, session: $1 as! KeyboardReleaseSessionBase) })
          .run()
    default:
      throw HandleMethodError.unknownMethod
    }
  }
}

internal protocol KeyboardPressSession: ServerSessionUnary {}

fileprivate final class KeyboardPressSessionBase: ServerSessionUnaryBase<KeyStroke, KeyboardResponse>, KeyboardPressSession {}

internal protocol KeyboardReleaseSession: ServerSessionUnary {}

fileprivate final class KeyboardReleaseSessionBase: ServerSessionUnaryBase<KeyStroke, KeyboardResponse>, KeyboardReleaseSession {}

