// Autogenerated from Pigeon (v26.0.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation

#if os(iOS)
  import Flutter
#elseif os(macOS)
  import FlutterMacOS
#else
  #error("Unsupported platform.")
#endif

/// Error class for passing custom error details to Dart side.
final class PigeonError: Error {
  let code: String
  let message: String?
  let details: Sendable?

  init(code: String, message: String?, details: Sendable?) {
    self.code = code
    self.message = message
    self.details = details
  }

  var localizedDescription: String {
    return
      "PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
  }
}

private func wrapResult(_ result: Any?) -> [Any?] {
  return [result]
}

private func wrapError(_ error: Any) -> [Any?] {
  if let pigeonError = error as? PigeonError {
    return [
      pigeonError.code,
      pigeonError.message,
      pigeonError.details,
    ]
  }
  if let flutterError = error as? FlutterError {
    return [
      flutterError.code,
      flutterError.message,
      flutterError.details,
    ]
  }
  return [
    "\(error)",
    "\(type(of: error))",
    "Stacktrace: \(Thread.callStackSymbols)",
  ]
}

private func createConnectionError(withChannelName channelName: String) -> PigeonError {
  return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "")
}

private func isNullish(_ value: Any?) -> Bool {
  return value is NSNull || value == nil
}

private func nilOrValue<T>(_ value: Any?) -> T? {
  if value is NSNull { return nil }
  return value as! T?
}


private class FlutterCommunicatorPigeonCodecReader: FlutterStandardReader {
}

private class FlutterCommunicatorPigeonCodecWriter: FlutterStandardWriter {
}

private class FlutterCommunicatorPigeonCodecReaderWriter: FlutterStandardReaderWriter {
  override func reader(with data: Data) -> FlutterStandardReader {
    return FlutterCommunicatorPigeonCodecReader(data: data)
  }

  override func writer(with data: NSMutableData) -> FlutterStandardWriter {
    return FlutterCommunicatorPigeonCodecWriter(data: data)
  }
}

class FlutterCommunicatorPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
  static let shared = FlutterCommunicatorPigeonCodec(readerWriter: FlutterCommunicatorPigeonCodecReaderWriter())
}

/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol WatchRecorderHostAPI {
  func startRecording() throws
  func stopRecording() throws
  func sendAudioData(audioData: FlutterStandardTypedData) throws
  func sendAudioChunk(audioChunk: FlutterStandardTypedData, chunkIndex: Int64, isLast: Bool, sampleRate: Double) throws
  func isWatchPaired() throws -> Bool
  func isWatchReachable() throws -> Bool
  func isWatchSessionSupported() throws -> Bool
  func isWatchAppInstalled() throws -> Bool
  func requestWatchMicrophonePermission() throws
  func requestMainAppMicrophonePermission() throws
  func checkMainAppMicrophonePermission() throws -> Bool
  func getWatchBatteryLevel() throws -> Double
  func getWatchBatteryState() throws -> Int64
  func requestWatchBatteryUpdate() throws
  func getWatchInfo() throws -> [String: String]
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class WatchRecorderHostAPISetup {
  static var codec: FlutterStandardMessageCodec { FlutterCommunicatorPigeonCodec.shared }
  /// Sets up an instance of `WatchRecorderHostAPI` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: WatchRecorderHostAPI?, messageChannelSuffix: String = "") {
    let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
    let startRecordingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.startRecording\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      startRecordingChannel.setMessageHandler { _, reply in
        do {
          try api.startRecording()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      startRecordingChannel.setMessageHandler(nil)
    }
    let stopRecordingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.stopRecording\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      stopRecordingChannel.setMessageHandler { _, reply in
        do {
          try api.stopRecording()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      stopRecordingChannel.setMessageHandler(nil)
    }
    let sendAudioDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.sendAudioData\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      sendAudioDataChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let audioDataArg = args[0] as! FlutterStandardTypedData
        do {
          try api.sendAudioData(audioData: audioDataArg)
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      sendAudioDataChannel.setMessageHandler(nil)
    }
    let sendAudioChunkChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.sendAudioChunk\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      sendAudioChunkChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let audioChunkArg = args[0] as! FlutterStandardTypedData
        let chunkIndexArg = args[1] as! Int64
        let isLastArg = args[2] as! Bool
        let sampleRateArg = args[3] as! Double
        do {
          try api.sendAudioChunk(audioChunk: audioChunkArg, chunkIndex: chunkIndexArg, isLast: isLastArg, sampleRate: sampleRateArg)
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      sendAudioChunkChannel.setMessageHandler(nil)
    }
    let isWatchPairedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.isWatchPaired\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      isWatchPairedChannel.setMessageHandler { _, reply in
        do {
          let result = try api.isWatchPaired()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      isWatchPairedChannel.setMessageHandler(nil)
    }
    let isWatchReachableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.isWatchReachable\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      isWatchReachableChannel.setMessageHandler { _, reply in
        do {
          let result = try api.isWatchReachable()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      isWatchReachableChannel.setMessageHandler(nil)
    }
    let isWatchSessionSupportedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.isWatchSessionSupported\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      isWatchSessionSupportedChannel.setMessageHandler { _, reply in
        do {
          let result = try api.isWatchSessionSupported()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      isWatchSessionSupportedChannel.setMessageHandler(nil)
    }
    let isWatchAppInstalledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.isWatchAppInstalled\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      isWatchAppInstalledChannel.setMessageHandler { _, reply in
        do {
          let result = try api.isWatchAppInstalled()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      isWatchAppInstalledChannel.setMessageHandler(nil)
    }
    let requestWatchMicrophonePermissionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.requestWatchMicrophonePermission\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      requestWatchMicrophonePermissionChannel.setMessageHandler { _, reply in
        do {
          try api.requestWatchMicrophonePermission()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      requestWatchMicrophonePermissionChannel.setMessageHandler(nil)
    }
    let requestMainAppMicrophonePermissionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.requestMainAppMicrophonePermission\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      requestMainAppMicrophonePermissionChannel.setMessageHandler { _, reply in
        do {
          try api.requestMainAppMicrophonePermission()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      requestMainAppMicrophonePermissionChannel.setMessageHandler(nil)
    }
    let checkMainAppMicrophonePermissionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.checkMainAppMicrophonePermission\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      checkMainAppMicrophonePermissionChannel.setMessageHandler { _, reply in
        do {
          let result = try api.checkMainAppMicrophonePermission()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      checkMainAppMicrophonePermissionChannel.setMessageHandler(nil)
    }
    let getWatchBatteryLevelChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.getWatchBatteryLevel\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getWatchBatteryLevelChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getWatchBatteryLevel()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getWatchBatteryLevelChannel.setMessageHandler(nil)
    }
    let getWatchBatteryStateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.getWatchBatteryState\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getWatchBatteryStateChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getWatchBatteryState()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getWatchBatteryStateChannel.setMessageHandler(nil)
    }
    let requestWatchBatteryUpdateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.requestWatchBatteryUpdate\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      requestWatchBatteryUpdateChannel.setMessageHandler { _, reply in
        do {
          try api.requestWatchBatteryUpdate()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      requestWatchBatteryUpdateChannel.setMessageHandler(nil)
    }
    let getWatchInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watch.WatchRecorderHostAPI.getWatchInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getWatchInfoChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getWatchInfo()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getWatchInfoChannel.setMessageHandler(nil)
    }
  }
}
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol WatchRecorderFlutterAPIProtocol {
  func onRecordingStarted(completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onRecordingStopped(completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onAudioData(audioData audioDataArg: FlutterStandardTypedData, completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onAudioChunk(audioChunk audioChunkArg: FlutterStandardTypedData, chunkIndex chunkIndexArg: Int64, isLast isLastArg: Bool, sampleRate sampleRateArg: Double, completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onRecordingError(error errorArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onMicrophonePermissionResult(granted grantedArg: Bool, completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onMainAppMicrophonePermissionResult(granted grantedArg: Bool, completion: @escaping (Result<Void, PigeonError>) -> Void)
  func onWatchBatteryUpdate(batteryLevel batteryLevelArg: Double, batteryState batteryStateArg: Int64, completion: @escaping (Result<Void, PigeonError>) -> Void)
}
class WatchRecorderFlutterAPI: WatchRecorderFlutterAPIProtocol {
  private let binaryMessenger: FlutterBinaryMessenger
  private let messageChannelSuffix: String
  init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") {
    self.binaryMessenger = binaryMessenger
    self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
  }
  var codec: FlutterCommunicatorPigeonCodec {
    return FlutterCommunicatorPigeonCodec.shared
  }
  func onRecordingStarted(completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onRecordingStarted\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage(nil) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onRecordingStopped(completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onRecordingStopped\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage(nil) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onAudioData(audioData audioDataArg: FlutterStandardTypedData, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onAudioData\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([audioDataArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onAudioChunk(audioChunk audioChunkArg: FlutterStandardTypedData, chunkIndex chunkIndexArg: Int64, isLast isLastArg: Bool, sampleRate sampleRateArg: Double, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onAudioChunk\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([audioChunkArg, chunkIndexArg, isLastArg, sampleRateArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onRecordingError(error errorArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onRecordingError\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([errorArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onMicrophonePermissionResult(granted grantedArg: Bool, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onMicrophonePermissionResult\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([grantedArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onMainAppMicrophonePermissionResult(granted grantedArg: Bool, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onMainAppMicrophonePermissionResult\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([grantedArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
  func onWatchBatteryUpdate(batteryLevel batteryLevelArg: Double, batteryState batteryStateArg: Int64, completion: @escaping (Result<Void, PigeonError>) -> Void) {
    let channelName: String = "dev.flutter.pigeon.watch.WatchRecorderFlutterAPI.onWatchBatteryUpdate\(messageChannelSuffix)"
    let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([batteryLevelArg, batteryStateArg] as [Any?]) { response in
      guard let listResponse = response as? [Any?] else {
        completion(.failure(createConnectionError(withChannelName: channelName)))
        return
      }
      if listResponse.count > 1 {
        let code: String = listResponse[0] as! String
        let message: String? = nilOrValue(listResponse[1])
        let details: String? = nilOrValue(listResponse[2])
        completion(.failure(PigeonError(code: code, message: message, details: details)))
      } else {
        completion(.success(()))
      }
    }
  }
}
