// Autogenerated from Pigeon (v26.3.4), 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

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)",
    "\(Swift.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 func doubleEqualsNetwork(_ lhs: Double, _ rhs: Double) -> Bool {
  return (lhs.isNaN && rhs.isNaN) || lhs == rhs
}

private func doubleHashNetwork(_ value: Double, _ hasher: inout Hasher) {
  if value.isNaN {
    hasher.combine(0x7FF8000000000000)
  } else {
    // Normalize -0.0 to 0.0
    hasher.combine(value == 0 ? 0 : value)
  }
}

func deepEqualsNetwork(_ lhs: Any?, _ rhs: Any?) -> Bool {
  let cleanLhs = nilOrValue(lhs) as Any?
  let cleanRhs = nilOrValue(rhs) as Any?
  switch (cleanLhs, cleanRhs) {
  case (nil, nil):
    return true

  case (nil, _), (_, nil):
    return false

  case (let lhs as AnyObject, let rhs as AnyObject) where lhs === rhs:
    return true

  case is (Void, Void):
    return true

  case (let lhsArray, let rhsArray) as ([Any?], [Any?]):
    guard lhsArray.count == rhsArray.count else { return false }
    for (index, element) in lhsArray.enumerated() {
      if !deepEqualsNetwork(element, rhsArray[index]) {
        return false
      }
    }
    return true

  case (let lhsArray, let rhsArray) as ([Double], [Double]):
    guard lhsArray.count == rhsArray.count else { return false }
    for (index, element) in lhsArray.enumerated() {
      if !doubleEqualsNetwork(element, rhsArray[index]) {
        return false
      }
    }
    return true

  case (let lhsDictionary, let rhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]):
    guard lhsDictionary.count == rhsDictionary.count else { return false }
    for (lhsKey, lhsValue) in lhsDictionary {
      var found = false
      for (rhsKey, rhsValue) in rhsDictionary {
        if deepEqualsNetwork(lhsKey, rhsKey) {
          if deepEqualsNetwork(lhsValue, rhsValue) {
            found = true
            break
          } else {
            return false
          }
        }
      }
      if !found { return false }
    }
    return true

  case (let lhs as Double, let rhs as Double):
    return doubleEqualsNetwork(lhs, rhs)

  case (let lhsHashable, let rhsHashable) as (AnyHashable, AnyHashable):
    return lhsHashable == rhsHashable

  default:
    return false
  }
}

func deepHashNetwork(value: Any?, hasher: inout Hasher) {
  let cleanValue = nilOrValue(value) as Any?
  if let cleanValue = cleanValue {
    if let doubleValue = cleanValue as? Double {
      doubleHashNetwork(doubleValue, &hasher)
    } else if let valueList = cleanValue as? [Any?] {
      for item in valueList {
        deepHashNetwork(value: item, hasher: &hasher)
      }
    } else if let valueList = cleanValue as? [Double] {
      for item in valueList {
        doubleHashNetwork(item, &hasher)
      }
    } else if let valueDict = cleanValue as? [AnyHashable: Any?] {
      var result = 0
      for (key, value) in valueDict {
        var entryKeyHasher = Hasher()
        deepHashNetwork(value: key, hasher: &entryKeyHasher)
        var entryValueHasher = Hasher()
        deepHashNetwork(value: value, hasher: &entryValueHasher)
        result = result &+ ((entryKeyHasher.finalize() &* 31) ^ entryValueHasher.finalize())
      }
      hasher.combine(result)
    } else if let hashableValue = cleanValue as? AnyHashable {
      hasher.combine(hashableValue)
    } else {
      hasher.combine(String(describing: cleanValue))
    }
  } else {
    hasher.combine(0)
  }
}


/// Generated class from Pigeon that represents data sent in messages.
struct ClientCertData: Hashable {
  var data: FlutterStandardTypedData
  var password: String


  // swift-format-ignore: AlwaysUseLowerCamelCase
  static func fromList(_ pigeonVar_list: [Any?]) -> ClientCertData? {
    let data = pigeonVar_list[0] as! FlutterStandardTypedData
    let password = pigeonVar_list[1] as! String

    return ClientCertData(
      data: data,
      password: password
    )
  }
  func toList() -> [Any?] {
    return [
      data,
      password,
    ]
  }
  static func == (lhs: ClientCertData, rhs: ClientCertData) -> Bool {
    if Swift.type(of: lhs) != Swift.type(of: rhs) {
      return false
    }
    return deepEqualsNetwork(lhs.data, rhs.data) && deepEqualsNetwork(lhs.password, rhs.password)
  }

  func hash(into hasher: inout Hasher) {
    hasher.combine("ClientCertData")
    deepHashNetwork(value: data, hasher: &hasher)
    deepHashNetwork(value: password, hasher: &hasher)
  }
}

/// Generated class from Pigeon that represents data sent in messages.
struct ClientCertPrompt: Hashable {
  var title: String
  var message: String
  var cancel: String
  var confirm: String


  // swift-format-ignore: AlwaysUseLowerCamelCase
  static func fromList(_ pigeonVar_list: [Any?]) -> ClientCertPrompt? {
    let title = pigeonVar_list[0] as! String
    let message = pigeonVar_list[1] as! String
    let cancel = pigeonVar_list[2] as! String
    let confirm = pigeonVar_list[3] as! String

    return ClientCertPrompt(
      title: title,
      message: message,
      cancel: cancel,
      confirm: confirm
    )
  }
  func toList() -> [Any?] {
    return [
      title,
      message,
      cancel,
      confirm,
    ]
  }
  static func == (lhs: ClientCertPrompt, rhs: ClientCertPrompt) -> Bool {
    if Swift.type(of: lhs) != Swift.type(of: rhs) {
      return false
    }
    return deepEqualsNetwork(lhs.title, rhs.title) && deepEqualsNetwork(lhs.message, rhs.message) && deepEqualsNetwork(lhs.cancel, rhs.cancel) && deepEqualsNetwork(lhs.confirm, rhs.confirm)
  }

  func hash(into hasher: inout Hasher) {
    hasher.combine("ClientCertPrompt")
    deepHashNetwork(value: title, hasher: &hasher)
    deepHashNetwork(value: message, hasher: &hasher)
    deepHashNetwork(value: cancel, hasher: &hasher)
    deepHashNetwork(value: confirm, hasher: &hasher)
  }
}

private class NetworkPigeonCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
    case 129:
      return ClientCertData.fromList(self.readValue() as! [Any?])
    case 130:
      return ClientCertPrompt.fromList(self.readValue() as! [Any?])
    default:
      return super.readValue(ofType: type)
    }
  }
}

private class NetworkPigeonCodecWriter: FlutterStandardWriter {
  override func writeValue(_ value: Any) {
    if let value = value as? ClientCertData {
      super.writeByte(129)
      super.writeValue(value.toList())
    } else if let value = value as? ClientCertPrompt {
      super.writeByte(130)
      super.writeValue(value.toList())
    } else {
      super.writeValue(value)
    }
  }
}

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

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

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


/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol NetworkApi {
  func addCertificate(clientData: ClientCertData, completion: @escaping (Result<Void, Error>) -> Void)
  func selectCertificate(promptText: ClientCertPrompt, completion: @escaping (Result<Void, Error>) -> Void)
  func removeCertificate(completion: @escaping (Result<Void, Error>) -> Void)
  func hasCertificate() throws -> Bool
  func getClientPointer() throws -> Int64
  func setRequestHeaders(headers: [String: String], serverUrls: [String], token: String?) throws
  func getAppGroupId() throws -> String
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class NetworkApiSetup {
  static var codec: FlutterStandardMessageCodec { NetworkPigeonCodec.shared }
  /// Sets up an instance of `NetworkApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NetworkApi?, messageChannelSuffix: String = "") {
    let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
    let addCertificateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.addCertificate\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      addCertificateChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let clientDataArg = args[0] as! ClientCertData
        api.addCertificate(clientData: clientDataArg) { result in
          switch result {
          case .success:
            reply(wrapResult(nil))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      addCertificateChannel.setMessageHandler(nil)
    }
    let selectCertificateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.selectCertificate\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      selectCertificateChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let promptTextArg = args[0] as! ClientCertPrompt
        api.selectCertificate(promptText: promptTextArg) { result in
          switch result {
          case .success:
            reply(wrapResult(nil))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      selectCertificateChannel.setMessageHandler(nil)
    }
    let removeCertificateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.removeCertificate\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      removeCertificateChannel.setMessageHandler { _, reply in
        api.removeCertificate { result in
          switch result {
          case .success:
            reply(wrapResult(nil))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      removeCertificateChannel.setMessageHandler(nil)
    }
    let hasCertificateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.hasCertificate\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      hasCertificateChannel.setMessageHandler { _, reply in
        do {
          let result = try api.hasCertificate()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      hasCertificateChannel.setMessageHandler(nil)
    }
    let getClientPointerChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.getClientPointer\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getClientPointerChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getClientPointer()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getClientPointerChannel.setMessageHandler(nil)
    }
    let setRequestHeadersChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.setRequestHeaders\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      setRequestHeadersChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let headersArg = args[0] as! [String: String]
        let serverUrlsArg = args[1] as! [String]
        let tokenArg: String? = nilOrValue(args[2])
        do {
          try api.setRequestHeaders(headers: headersArg, serverUrls: serverUrlsArg, token: tokenArg)
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      setRequestHeadersChannel.setMessageHandler(nil)
    }
    let getAppGroupIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.getAppGroupId\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getAppGroupIdChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getAppGroupId()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getAppGroupIdChannel.setMessageHandler(nil)
    }
  }
}
