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

package app.alextran.immich.core

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 NetworkPigeonUtils {

  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 doubleEquals(a: Double, b: Double): Boolean {
    // Normalize -0.0 to 0.0 and handle NaN equality.
    return (if (a == 0.0) 0.0 else a) == (if (b == 0.0) 0.0 else b) || (a.isNaN() && b.isNaN())
  }

  fun floatEquals(a: Float, b: Float): Boolean {
    // Normalize -0.0 to 0.0 and handle NaN equality.
    return (if (a == 0.0f) 0.0f else a) == (if (b == 0.0f) 0.0f else b) || (a.isNaN() && b.isNaN())
  }

  fun doubleHash(d: Double): Int {
    // Normalize -0.0 to 0.0 and handle NaN to ensure consistent hash codes.
    val normalized = if (d == 0.0) 0.0 else d
    val bits = java.lang.Double.doubleToLongBits(normalized)
    return (bits xor (bits ushr 32)).toInt()
  }

  fun floatHash(f: Float): Int {
    // Normalize -0.0 to 0.0 and handle NaN to ensure consistent hash codes.
    val normalized = if (f == 0.0f) 0.0f else f
    return java.lang.Float.floatToIntBits(normalized)
  }

  fun deepEquals(a: Any?, b: Any?): Boolean {
    if (a === b) {
      return true
    }
    if (a == null || b == null) {
      return false
    }
    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) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!doubleEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is FloatArray && b is FloatArray) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!floatEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is Array<*> && b is Array<*>) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!deepEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is List<*> && b is List<*>) {
      if (a.size != b.size) return false
      val iterA = a.iterator()
      val iterB = b.iterator()
      while (iterA.hasNext() && iterB.hasNext()) {
        if (!deepEquals(iterA.next(), iterB.next())) return false
      }
      return true
    }
    if (a is Map<*, *> && b is Map<*, *>) {
      if (a.size != b.size) return false
      for (entry in a) {
        val key = entry.key
        var found = false
        for (bEntry in b) {
          if (deepEquals(key, bEntry.key)) {
            if (deepEquals(entry.value, bEntry.value)) {
              found = true
              break
            } else {
              return false
            }
          }
        }
        if (!found) return false
      }
      return true
    }
    if (a is Double && b is Double) {
      return doubleEquals(a, b)
    }
    if (a is Float && b is Float) {
      return floatEquals(a, b)
    }
    return a == b
  }

  fun deepHash(value: Any?): Int {
    return when (value) {
      null -> 0
      is ByteArray -> value.contentHashCode()
      is IntArray -> value.contentHashCode()
      is LongArray -> value.contentHashCode()
      is DoubleArray -> {
        var result = 1
        for (item in value) {
          result = 31 * result + doubleHash(item)
        }
        result
      }
      is FloatArray -> {
        var result = 1
        for (item in value) {
          result = 31 * result + floatHash(item)
        }
        result
      }
      is Array<*> -> {
        var result = 1
        for (item in value) {
          result = 31 * result + deepHash(item)
        }
        result
      }
      is List<*> -> {
        var result = 1
        for (item in value) {
          result = 31 * result + deepHash(item)
        }
        result
      }
      is Map<*, *> -> {
        var result = 0
        for (entry in value) {
          result += ((deepHash(entry.key) * 31) xor deepHash(entry.value))
        }
        result
      }
      is Double -> doubleHash(value)
      is Float -> floatHash(value)
      else -> value.hashCode()
    }
  }

}

/**
 * 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
) : RuntimeException()

/** Generated class from Pigeon that represents data sent in messages. */
data class ClientCertData (
  val data: ByteArray,
  val password: String
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): ClientCertData {
      val data = pigeonVar_list[0] as ByteArray
      val password = pigeonVar_list[1] as String
      return ClientCertData(data, password)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      data,
      password,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as ClientCertData
    return NetworkPigeonUtils.deepEquals(this.data, other.data) && NetworkPigeonUtils.deepEquals(this.password, other.password)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + NetworkPigeonUtils.deepHash(this.data)
    result = 31 * result + NetworkPigeonUtils.deepHash(this.password)
    return result
  }
}

/** Generated class from Pigeon that represents data sent in messages. */
data class ClientCertPrompt (
  val title: String,
  val message: String,
  val cancel: String,
  val confirm: String
)
 {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): ClientCertPrompt {
      val title = pigeonVar_list[0] as String
      val message = pigeonVar_list[1] as String
      val cancel = pigeonVar_list[2] as String
      val confirm = pigeonVar_list[3] as String
      return ClientCertPrompt(title, message, cancel, confirm)
    }
  }
  fun toList(): List<Any?> {
    return listOf(
      title,
      message,
      cancel,
      confirm,
    )
  }
  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as ClientCertPrompt
    return NetworkPigeonUtils.deepEquals(this.title, other.title) && NetworkPigeonUtils.deepEquals(this.message, other.message) && NetworkPigeonUtils.deepEquals(this.cancel, other.cancel) && NetworkPigeonUtils.deepEquals(this.confirm, other.confirm)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + NetworkPigeonUtils.deepHash(this.title)
    result = 31 * result + NetworkPigeonUtils.deepHash(this.message)
    result = 31 * result + NetworkPigeonUtils.deepHash(this.cancel)
    result = 31 * result + NetworkPigeonUtils.deepHash(this.confirm)
    return result
  }
}
private open class NetworkPigeonCodec : StandardMessageCodec() {
  override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
    return when (type) {
      129.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          ClientCertData.fromList(it)
        }
      }
      130.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          ClientCertPrompt.fromList(it)
        }
      }
      else -> super.readValueOfType(type, buffer)
    }
  }
  override fun writeValue(stream: ByteArrayOutputStream, value: Any?)   {
    when (value) {
      is ClientCertData -> {
        stream.write(129)
        writeValue(stream, value.toList())
      }
      is ClientCertPrompt -> {
        stream.write(130)
        writeValue(stream, value.toList())
      }
      else -> super.writeValue(stream, value)
    }
  }
}


/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface NetworkApi {
  fun addCertificate(clientData: ClientCertData, callback: (Result<Unit>) -> Unit)
  fun selectCertificate(promptText: ClientCertPrompt, callback: (Result<Unit>) -> Unit)
  fun removeCertificate(callback: (Result<Unit>) -> Unit)
  fun hasCertificate(): Boolean
  fun getClientPointer(): Long
  fun setRequestHeaders(headers: Map<String, String>, serverUrls: List<String>, token: String?)

  companion object {
    /** The codec used by NetworkApi. */
    val codec: MessageCodec<Any?> by lazy {
      NetworkPigeonCodec()
    }
    /** Sets up an instance of `NetworkApi` to handle messages through the `binaryMessenger`. */
    @JvmOverloads
    fun setUp(binaryMessenger: BinaryMessenger, api: NetworkApi?, messageChannelSuffix: String = "") {
      val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.addCertificate$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val clientDataArg = args[0] as ClientCertData
            api.addCertificate(clientDataArg) { result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(NetworkPigeonUtils.wrapError(error))
              } else {
                reply.reply(NetworkPigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.selectCertificate$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val promptTextArg = args[0] as ClientCertPrompt
            api.selectCertificate(promptTextArg) { result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(NetworkPigeonUtils.wrapError(error))
              } else {
                reply.reply(NetworkPigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.removeCertificate$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            api.removeCertificate{ result: Result<Unit> ->
              val error = result.exceptionOrNull()
              if (error != null) {
                reply.reply(NetworkPigeonUtils.wrapError(error))
              } else {
                reply.reply(NetworkPigeonUtils.wrapResult(null))
              }
            }
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.hasCertificate$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> = try {
              listOf(api.hasCertificate())
            } catch (exception: Throwable) {
              NetworkPigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.getClientPointer$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> = try {
              listOf(api.getClientPointer())
            } catch (exception: Throwable) {
              NetworkPigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.setRequestHeaders$separatedMessageChannelSuffix", codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val headersArg = args[0] as Map<String, String>
            val serverUrlsArg = args[1] as List<String>
            val tokenArg = args[2] as String?
            val wrapped: List<Any?> = try {
              api.setRequestHeaders(headersArg, serverUrlsArg, tokenArg)
              listOf(null)
            } catch (exception: Throwable) {
              NetworkPigeonUtils.wrapError(exception)
            }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
    }
  }
}
