// Autogenerated from Pigeon (v26.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

package com.navideck.universal_ble

import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MessageCodec
import io.flutter.plugin.common.StandardMethodCodec
import io.flutter.plugin.common.StandardMessageCodec
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
private object UniversalBlePigeonUtils {

  fun createConnectionError(channelName: String): FlutterError {
    return FlutterError("channel-error",  "Unable to establish connection on channel: '$channelName'.", "")  }

  fun wrapResult(result: Any?): List<Any?> {
    return listOf(result)
  }

  fun wrapError(exception: Throwable): List<Any?> {
    return if (exception is FlutterError) {
      listOf(
        exception.code,
        exception.message,
        exception.details
      )
    } else {
      listOf(
        exception.javaClass.simpleName,
        exception.toString(),
        "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
      )
    }
  }
  fun deepEquals(a: Any?, b: Any?): Boolean {
    if (a is ByteArray && b is ByteArray) {
        return a.contentEquals(b)
    }
    if (a is IntArray && b is IntArray) {
        return a.contentEquals(b)
    }
    if (a is LongArray && b is LongArray) {
        return a.contentEquals(b)
    }
    if (a is DoubleArray && b is DoubleArray) {
        return a.contentEquals(b)
    }
    if (a is Array<*> && b is Array<*>) {
      return a.size == b.size &&
          a.indices.all{ deepEquals(a[it], b[it]) }
    }
    if (a is List<*> && b is List<*>) {
      return a.size == b.size &&
          a.indices.all{ deepEquals(a[it], b[it]) }
    }
    if (a is Map<*, *> && b is Map<*, *>) {
      return a.size == b.size && a.all {
          (b as Map<Any?, Any?>).contains(it.key) &&
          deepEquals(it.value, b[it.key])
      }
    }
    return a == b
  }
      
}

/**
 * Error class for passing custom error details to Flutter via a thrown PlatformException.
 * @property code The error code.
 * @property message The error message.
 * @property details The error details. Must be a datatype supported by the api codec.
 */
class FlutterError (
  val code: String,
  override val message: String? = null,
  val details: Any? = null
) : Throwable()

enum class UniversalBleLogLevel(val raw: Int) {
  NONE(0),
  ERROR(1),
  WARNING(2),
  INFO(3),
  DEBUG(4),
  VERBOSE(5);

  companion object {
    fun ofRaw(raw: Int): UniversalBleLogLevel? {
      return values().firstOrNull { it.raw == raw }
    }
  }
}

/** Unified error codes for all platforms */
enum class UniversalBleErrorCode(val raw: Int) {
  UNKNOWN_ERROR(0),
  FAILED(1),
  NOT_SUPPORTED(2),
  NOT_IMPLEMENTED(3),
  CHANNEL_ERROR(4),
  BLUETOOTH_NOT_AVAILABLE(5),
  BLUETOOTH_NOT_ENABLED(6),
  BLUETOOTH_NOT_ALLOWED(7),
  BLUETOOTH_UNAUTHORIZED(8),
  DEVICE_DISCONNECTED(9),
  CONNECTION_TIMEOUT(10),
  CONNECTION_FAILED(11),
  CONNECTION_REJECTED(12),
  CONNECTION_LIMIT_EXCEEDED(13),
  CONNECTION_ALREADY_EXISTS(14),
  CONNECTION_TERMINATED(15),
  CONNECTION_IN_PROGRESS(16),
  ILLEGAL_ARGUMENT(17),
  DEVICE_NOT_FOUND(18),
  SERVICE_NOT_FOUND(19),
  CHARACTERISTIC_NOT_FOUND(20),
  INVALID_SERVICE_UUID(21),
  INVALID_CHARACTERISTIC_UUID(22),
  INVALID_OFFSET(23),
  INVALID_ATTRIBUTE_LENGTH(24),
  INVALID_PDU(25),
  INVALID_HANDLE(26),
  READ_FAILED(27),
  READ_NOT_PERMITTED(28),
  WRITE_FAILED(29),
  WRITE_NOT_PERMITTED(30),
  WRITE_REQUEST_BUSY(31),
  INVALID_ACTION(32),
  OPERATION_NOT_SUPPORTED(33),
  OPERATION_TIMEOUT(34),
  OPERATION_CANCELLED(35),
  OPERATION_IN_PROGRESS(36),
  CHARACTERISTIC_DOES_NOT_SUPPORT_READ(37),
  CHARACTERISTIC_DOES_NOT_SUPPORT_WRITE(38),
  CHARACTERISTIC_DOES_NOT_SUPPORT_WRITE_WITHOUT_RESPONSE(39),
  CHARACTERISTIC_DOES_NOT_SUPPORT_NOTIFY(40),
  CHARACTERISTIC_DOES_NOT_SUPPORT_INDICATE(41),
  NOT_PAIRED(42),
  NOT_PAIRABLE(43),
  ALREADY_PAIRED(44),
  PAIRING_FAILED(45),
  PAIRING_CANCELLED(46),
  PAIRING_TIMEOUT(47),
  PAIRING_NOT_ALLOWED(48),
  AUTHENTICATION_FAILURE(49),
  INSUFFICIENT_AUTHENTICATION(50),
  INSUFFICIENT_AUTHORIZATION(51),
  INSUFFICIENT_ENCRYPTION(52),
  INSUFFICIENT_KEY_SIZE(53),
  PROTECTION_LEVEL_NOT_MET(54),
  ACCESS_DENIED(55),
  UNPAIRING_FAILED(56),
  ALREADY_UNPAIRED(57),
  SCAN_FAILED(58),
  STOPPING_SCAN_IN_PROGRESS(59),
  WEB_BLUETOOTH_GLOBALLY_DISABLED(60);

  companion object {
    fun ofRaw(raw: Int): UniversalBleErrorCode? {
      return values().firstOrNull { it.raw == raw }
    }
  }
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalBleScanResult (
  val deviceId: String,
  val name: String? = null,
  val isPaired: Boolean? = null,
  val rssi: Long? = null,
  val manufacturerDataList: List<UniversalManufacturerData>? = null,
  val services: List<String>? = null,
  val timestamp: Long? = null
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalBleScanResult {
      val deviceId = pigeonVar_list[0] as String
      val name = pigeonVar_list[1] as String?
      val isPaired = pigeonVar_list[2] as Boolean?
      val rssi = pigeonVar_list[3] as Long?
      val manufacturerDataList = pigeonVar_list[4] as List<UniversalManufacturerData>?
      val services = pigeonVar_list[5] as List<String>?
      val timestamp = pigeonVar_list[6] as Long?
      return UniversalBleScanResult(deviceId, name, isPaired, rssi, manufacturerDataList, services, timestamp)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      deviceId,
      name,
      isPaired,
      rssi,
      manufacturerDataList,
      services,
      timestamp,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalBleScanResult) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalBleService (
  val uuid: String,
  val characteristics: List<UniversalBleCharacteristic>? = null
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalBleService {
      val uuid = pigeonVar_list[0] as String
      val characteristics = pigeonVar_list[1] as List<UniversalBleCharacteristic>?
      return UniversalBleService(uuid, characteristics)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      uuid,
      characteristics,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalBleService) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalBleCharacteristic (
  val uuid: String,
  val properties: List<Long>,
  val descriptors: List<UniversalBleDescriptor>
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalBleCharacteristic {
      val uuid = pigeonVar_list[0] as String
      val properties = pigeonVar_list[1] as List<Long>
      val descriptors = pigeonVar_list[2] as List<UniversalBleDescriptor>
      return UniversalBleCharacteristic(uuid, properties, descriptors)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      uuid,
      properties,
      descriptors,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalBleCharacteristic) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalBleDescriptor (
  val uuid: String
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalBleDescriptor {
      val uuid = pigeonVar_list[0] as String
      return UniversalBleDescriptor(uuid)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      uuid,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalBleDescriptor) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/**
 * Scan Filters
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class UniversalScanFilter (
  val withServices: List<String>,
  val withNamePrefix: List<String>,
  val withManufacturerData: List<UniversalManufacturerDataFilter>
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalScanFilter {
      val withServices = pigeonVar_list[0] as List<String>
      val withNamePrefix = pigeonVar_list[1] as List<String>
      val withManufacturerData = pigeonVar_list[2] as List<UniversalManufacturerDataFilter>
      return UniversalScanFilter(withServices, withNamePrefix, withManufacturerData)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      withServices,
      withNamePrefix,
      withManufacturerData,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalScanFilter) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalManufacturerDataFilter (
  val companyIdentifier: Long,
  val data: ByteArray? = null,
  val mask: ByteArray? = null
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalManufacturerDataFilter {
      val companyIdentifier = pigeonVar_list[0] as Long
      val data = pigeonVar_list[1] as ByteArray?
      val mask = pigeonVar_list[2] as ByteArray?
      return UniversalManufacturerDataFilter(companyIdentifier, data, mask)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      companyIdentifier,
      data,
      mask,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalManufacturerDataFilter) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}

/** Generated class from Pigeon that represents data sent in messages. */
data class UniversalManufacturerData (
  val companyIdentifier: Long,
  val data: ByteArray
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): UniversalManufacturerData {
      val companyIdentifier = pigeonVar_list[0] as Long
      val data = pigeonVar_list[1] as ByteArray
      return UniversalManufacturerData(companyIdentifier, data)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      companyIdentifier,
      data,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other !is UniversalManufacturerData) {
      return false
    }
    if (this === other) {
      return true
    }
    return UniversalBlePigeonUtils.deepEquals(toList(), other.toList())  }

  override fun hashCode(): Int = toList().hashCode()
}
private open class UniversalBlePigeonCodec : StandardMessageCodec() {
  override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
    return when (type) {
      129.toByte() -> {
        return (readValue(buffer) as Long?)?.let {
          UniversalBleLogLevel.ofRaw(it.toInt())
        }
      }
      130.toByte() -> {
        return (readValue(buffer) as Long?)?.let {
          UniversalBleErrorCode.ofRaw(it.toInt())
        }
      }
      131.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalBleScanResult.fromList(it)
        }
      }
      132.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalBleService.fromList(it)
        }
      }
      133.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalBleCharacteristic.fromList(it)
        }
      }
      134.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalBleDescriptor.fromList(it)
        }
      }
      135.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalScanFilter.fromList(it)
        }
      }
      136.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalManufacturerDataFilter.fromList(it)
        }
      }
      137.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          UniversalManufacturerData.fromList(it)
        }
      }
      else -> super.readValueOfType(type, buffer)
    }
  }
  override fun writeValue(stream: ByteArrayOutputStream, value: Any?)   {
    when (value) {
      is UniversalBleLogLevel -> {
        stream.write(129)
        writeValue(stream, value.raw.toLong())
      }
      is UniversalBleErrorCode -> {
        stream.write(130)
        writeValue(stream, value.raw.toLong())
      }
      is UniversalBleScanResult -> {
        stream.write(131)
        writeValue(stream, value.toList())
      }
      is UniversalBleService -> {
        stream.write(132)
        writeValue(stream, value.toList())
      }
      is UniversalBleCharacteristic -> {
        stream.write(133)
        writeValue(stream, value.toList())
      }
      is UniversalBleDescriptor -> {
        stream.write(134)
        writeValue(stream, value.toList())
      }
      is UniversalScanFilter -> {
        stream.write(135)
        writeValue(stream, value.toList())
      }
      is UniversalManufacturerDataFilter -> {
        stream.write(136)
        writeValue(stream, value.toList())
      }
      is UniversalManufacturerData -> {
        stream.write(137)
        writeValue(stream, value.toList())
      }
      else -> super.writeValue(stream, value)
    }
  }
}


/**
 * Flutter -> Native
 *
 * Generated interface from Pigeon that represents a handler of messages from Flutter.
 */
interface UniversalBlePlatformChannel {
  fun getBluetoothAvailabilityState(callback: (Result<Long>) -> Unit)
  fun hasPermissions(withAndroidFineLocation: Boolean): Boolean
  fun requestPermissions(withAndroidFineLocation: Boolean, callback: (Result<Unit>) -> Unit)
  fun enableBluetooth(callback: (Result<Boolean>) -> Unit)
  fun disableBluetooth(callback: (Result<Boolean>) -> Unit)
  fun startScan(filter: UniversalScanFilter?)
  fun stopScan()
  fun isScanning(): Boolean
  fun connect(deviceId: String)
  fun disconnect(deviceId: String)
  fun setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Long, callback: (Result<Unit>) -> Unit)
  fun discoverServices(deviceId: String, withDescriptors: Boolean, callback: (Result<List<UniversalBleService>>) -> Unit)
  fun readValue(deviceId: String, service: String, characteristic: String, callback: (Result<ByteArray>) -> Unit)
  fun requestMtu(deviceId: String, expectedMtu: Long, callback: (Result<Long>) -> Unit)
  fun writeValue(deviceId: String, service: String, characteristic: String, value: ByteArray, bleOutputProperty: Long, callback: (Result<Unit>) -> Unit)
  fun isPaired(deviceId: String, callback: (Result<Boolean>) -> Unit)
  fun pair(deviceId: String, callback: (Result<Boolean>) -> Unit)
  fun unPair(deviceId: String)
  fun getSystemDevices(withServices: List<String>, callback: (Result<List<UniversalBleScanResult>>) -> Unit)
  fun getConnectionState(deviceId: String): Long
  fun setLogLevel(logLevel: UniversalBleLogLevel)

  companion object {
    /** The codec used by UniversalBlePlatformChannel. */
    val codec: MessageCodec<Any?> by lazy {
      UniversalBlePigeonCodec()
    }
    /** Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binaryMessenger`. */
    @JvmOverloads
    fun setUp(binaryMessenger: BinaryMessenger, api: UniversalBlePlatformChannel?, messageChannelSuffix: String = "") {
      val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            api.getBluetoothAvailabilityState{ result: Result<Long> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.hasPermissions$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val withAndroidFineLocationArg = args[0] as Boolean
            val wrapped: List<Any?> = try {
              listOf(api.hasPermissions(withAndroidFineLocationArg))
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestPermissions$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val withAndroidFineLocationArg = args[0] as Boolean
            api.requestPermissions(withAndroidFineLocationArg) { result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                reply.reply(UniversalBlePigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            api.enableBluetooth{ result: Result<Boolean> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disableBluetooth$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            api.disableBluetooth{ result: Result<Boolean> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val filterArg = args[0] as UniversalScanFilter?
            val wrapped: List<Any?> = try {
              api.startScan(filterArg)
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> = try {
              api.stopScan()
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isScanning$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> = try {
              listOf(api.isScanning())
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val wrapped: List<Any?> = try {
              api.connect(deviceIdArg)
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val wrapped: List<Any?> = try {
              api.disconnect(deviceIdArg)
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val serviceArg = args[1] as String
            val characteristicArg = args[2] as String
            val bleInputPropertyArg = args[3] as Long
            api.setNotifiable(deviceIdArg, serviceArg, characteristicArg, bleInputPropertyArg) { result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                reply.reply(UniversalBlePigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val withDescriptorsArg = args[1] as Boolean
            api.discoverServices(deviceIdArg, withDescriptorsArg) { result: Result<List<UniversalBleService>> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val serviceArg = args[1] as String
            val characteristicArg = args[2] as String
            api.readValue(deviceIdArg, serviceArg, characteristicArg) { result: Result<ByteArray> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val expectedMtuArg = args[1] as Long
            api.requestMtu(deviceIdArg, expectedMtuArg) { result: Result<Long> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val serviceArg = args[1] as String
            val characteristicArg = args[2] as String
            val valueArg = args[3] as ByteArray
            val bleOutputPropertyArg = args[4] as Long
            api.writeValue(deviceIdArg, serviceArg, characteristicArg, valueArg, bleOutputPropertyArg) { result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                reply.reply(UniversalBlePigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            api.isPaired(deviceIdArg) { result: Result<Boolean> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            api.pair(deviceIdArg) { result: Result<Boolean> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val wrapped: List<Any?> = try {
              api.unPair(deviceIdArg)
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getSystemDevices$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val withServicesArg = args[0] as List<String>
            api.getSystemDevices(withServicesArg) { result: Result<List<UniversalBleScanResult>> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(UniversalBlePigeonUtils.wrapError(error))
              } else {
                val data = result.getOrNull()
                reply.reply(UniversalBlePigeonUtils.wrapResult(data))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectionState$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val deviceIdArg = args[0] as String
            val wrapped: List<Any?> = try {
              listOf(api.getConnectionState(deviceIdArg))
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setLogLevel$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val logLevelArg = args[0] as UniversalBleLogLevel
            val wrapped: List<Any?> = try {
              api.setLogLevel(logLevelArg)
              listOf(null)
            } catch (exception: Throwable) {
              UniversalBlePigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
    }
  }
}
/**
 * Native -> Flutter
 *
 * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin.
 */
class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") {
  companion object {
    /** The codec used by UniversalBleCallbackChannel. */
    val codec: MessageCodec<Any?> by lazy {
      UniversalBlePigeonCodec()
    }
  }
  fun onAvailabilityChanged(stateArg: Long, callback: (Result<Unit>) -> Unit)
{
    val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
    val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged$separatedMessageChannelSuffix"
    val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
    channel.send(listOf(stateArg)) {
      if (it is List<*>) {
        if (it.size > 1) {
          callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
        } else {
          callback(Result.success(Unit))
        }
      } else {
        callback(Result.failure(UniversalBlePigeonUtils.createConnectionError(channelName)))
      } 
    }
  }
  fun onPairStateChange(deviceIdArg: String, isPairedArg: Boolean, errorArg: String?, callback: (Result<Unit>) -> Unit)
{
    val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
    val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange$separatedMessageChannelSuffix"
    val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
    channel.send(listOf(deviceIdArg, isPairedArg, errorArg)) {
      if (it is List<*>) {
        if (it.size > 1) {
          callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
        } else {
          callback(Result.success(Unit))
        }
      } else {
        callback(Result.failure(UniversalBlePigeonUtils.createConnectionError(channelName)))
      } 
    }
  }
  fun onScanResult(resultArg: UniversalBleScanResult, callback: (Result<Unit>) -> Unit)
{
    val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
    val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult$separatedMessageChannelSuffix"
    val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
    channel.send(listOf(resultArg)) {
      if (it is List<*>) {
        if (it.size > 1) {
          callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
        } else {
          callback(Result.success(Unit))
        }
      } else {
        callback(Result.failure(UniversalBlePigeonUtils.createConnectionError(channelName)))
      } 
    }
  }
  fun onValueChanged(deviceIdArg: String, characteristicIdArg: String, valueArg: ByteArray, timestampArg: Long?, callback: (Result<Unit>) -> Unit)
{
    val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
    val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged$separatedMessageChannelSuffix"
    val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
    channel.send(listOf(deviceIdArg, characteristicIdArg, valueArg, timestampArg)) {
      if (it is List<*>) {
        if (it.size > 1) {
          callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
        } else {
          callback(Result.success(Unit))
        }
      } else {
        callback(Result.failure(UniversalBlePigeonUtils.createConnectionError(channelName)))
      } 
    }
  }
  fun onConnectionChanged(deviceIdArg: String, connectedArg: Boolean, errorArg: String?, callback: (Result<Unit>) -> Unit)
{
    val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
    val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged$separatedMessageChannelSuffix"
    val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
    channel.send(listOf(deviceIdArg, connectedArg, errorArg)) {
      if (it is List<*>) {
        if (it.size > 1) {
          callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
        } else {
          callback(Result.success(Unit))
        }
      } else {
        callback(Result.failure(UniversalBlePigeonUtils.createConnectionError(channelName)))
      } 
    }
  }
}
