// 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 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 CoreApiPigeonCodecReader: FlutterStandardReader {
}

private class CoreApiPigeonCodecWriter: FlutterStandardWriter {
}

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

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

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

var coreApiPigeonMethodCodec = FlutterStandardMethodCodec(readerWriter: CoreApiPigeonCodecReaderWriter());

/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol CoreApi {
  func getApps() throws -> String?
  func getSystemLocale() throws -> String?
  func connect() throws -> Bool?
  func disconnect() throws -> Bool?
  func getRemoteIp() throws -> String?
  func getAdvertisingId() throws -> String?
  func moveTaskToBack() throws -> Bool?
  func isConnected() throws -> Bool?
  func getSimInfo() throws -> String?
  func reconnect() throws -> Bool?
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class CoreApiSetup {
  static var codec: FlutterStandardMessageCodec { CoreApiPigeonCodec.shared }
  /// Sets up an instance of `CoreApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: CoreApi?, messageChannelSuffix: String = "") {
    let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
    let getAppsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.getApps\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getAppsChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getApps()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getAppsChannel.setMessageHandler(nil)
    }
    let getSystemLocaleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.getSystemLocale\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getSystemLocaleChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getSystemLocale()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getSystemLocaleChannel.setMessageHandler(nil)
    }
    let connectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.connect\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      connectChannel.setMessageHandler { _, reply in
        do {
          let result = try api.connect()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      connectChannel.setMessageHandler(nil)
    }
    let disconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.disconnect\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      disconnectChannel.setMessageHandler { _, reply in
        do {
          let result = try api.disconnect()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      disconnectChannel.setMessageHandler(nil)
    }
    let getRemoteIpChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.getRemoteIp\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getRemoteIpChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getRemoteIp()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getRemoteIpChannel.setMessageHandler(nil)
    }
    let getAdvertisingIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.getAdvertisingId\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getAdvertisingIdChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getAdvertisingId()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getAdvertisingIdChannel.setMessageHandler(nil)
    }
    let moveTaskToBackChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.moveTaskToBack\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      moveTaskToBackChannel.setMessageHandler { _, reply in
        do {
          let result = try api.moveTaskToBack()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      moveTaskToBackChannel.setMessageHandler(nil)
    }
    let isConnectedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.isConnected\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      isConnectedChannel.setMessageHandler { _, reply in
        do {
          let result = try api.isConnected()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      isConnectedChannel.setMessageHandler(nil)
    }
    let getSimInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.getSimInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getSimInfoChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getSimInfo()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getSimInfoChannel.setMessageHandler(nil)
    }
    let reconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.app.xixi.nomo.CoreApi.reconnect\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      reconnectChannel.setMessageHandler { _, reply in
        do {
          let result = try api.reconnect()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      reconnectChannel.setMessageHandler(nil)
    }
  }
}

private class PigeonStreamHandler<ReturnType>: NSObject, FlutterStreamHandler {
  private let wrapper: PigeonEventChannelWrapper<ReturnType>
  private var pigeonSink: PigeonEventSink<ReturnType>? = nil

  init(wrapper: PigeonEventChannelWrapper<ReturnType>) {
    self.wrapper = wrapper
  }

  func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink)
    -> FlutterError?
  {
    pigeonSink = PigeonEventSink<ReturnType>(events)
    wrapper.onListen(withArguments: arguments, sink: pigeonSink!)
    return nil
  }

  func onCancel(withArguments arguments: Any?) -> FlutterError? {
    pigeonSink = nil
    wrapper.onCancel(withArguments: arguments)
    return nil
  }
}

class PigeonEventChannelWrapper<ReturnType> {
  func onListen(withArguments arguments: Any?, sink: PigeonEventSink<ReturnType>) {}
  func onCancel(withArguments arguments: Any?) {}
}

class PigeonEventSink<ReturnType> {
  private let sink: FlutterEventSink

  init(_ sink: @escaping FlutterEventSink) {
    self.sink = sink
  }

  func success(_ value: ReturnType) {
    sink(value)
  }

  func error(code: String, message: String?, details: Any?) {
    sink(FlutterError(code: code, message: message, details: details))
  }

  func endOfStream() {
    sink(FlutterEndOfEventStream)
  }

}

class OnEventChangeStreamHandler: PigeonEventChannelWrapper<String> {
  static func register(with messenger: FlutterBinaryMessenger,
                      instanceName: String = "",
                      streamHandler: OnEventChangeStreamHandler) {
    var channelName = "dev.flutter.pigeon.app.xixi.nomo.CoreChangeEventApi.onEventChange"
    if !instanceName.isEmpty {
      channelName += ".\(instanceName)"
    }
    let internalStreamHandler = PigeonStreamHandler<String>(wrapper: streamHandler)
    let channel = FlutterEventChannel(name: channelName, binaryMessenger: messenger, codec: coreApiPigeonMethodCodec)
    channel.setStreamHandler(internalStreamHandler)
  }
}
      
