// Copyright 2023-2025 BenderBlog Rodriguez and contributors
// Copyright 2025 Traintime PDA authors.
// SPDX-License-Identifier: MPL-2.0
// 
// Autogenerated from Pigeon (v16.0.3), 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 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?
}

/// Generated class from Pigeon that represents data sent in messages.
struct FileToGroupID {
  var appid: String
  var fileName: String
  var data: String

  static func fromList(_ list: [Any?]) -> FileToGroupID? {
    let appid = list[0] as! String
    let fileName = list[1] as! String
    let data = list[2] as! String

    return FileToGroupID(
      appid: appid,
      fileName: fileName,
      data: data
    )
  }
  func toList() -> [Any?] {
    return [
      appid,
      fileName,
      data,
    ]
  }
}

private class SaveToGroupIdSwiftApiCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
      case 128:
        return FileToGroupID.fromList(self.readValue() as! [Any?])
      default:
        return super.readValue(ofType: type)
    }
  }
}

private class SaveToGroupIdSwiftApiCodecWriter: FlutterStandardWriter {
  override func writeValue(_ value: Any) {
    if let value = value as? FileToGroupID {
      super.writeByte(128)
      super.writeValue(value.toList())
    } else {
      super.writeValue(value)
    }
  }
}

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

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

class SaveToGroupIdSwiftApiCodec: FlutterStandardMessageCodec {
  static let shared = SaveToGroupIdSwiftApiCodec(readerWriter: SaveToGroupIdSwiftApiCodecReaderWriter())
}

/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol SaveToGroupIdSwiftApi {
  func getHostLanguage() throws -> String
  func saveToGroupId(data: FileToGroupID, completion: @escaping (Result<Bool, Error>) -> Void)
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class SaveToGroupIdSwiftApiSetup {
  /// The codec used by SaveToGroupIdSwiftApi.
  static var codec: FlutterStandardMessageCodec { SaveToGroupIdSwiftApiCodec.shared }
  /// Sets up an instance of `SaveToGroupIdSwiftApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: SaveToGroupIdSwiftApi?) {
    let getHostLanguageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watermeter.SaveToGroupIdSwiftApi.getHostLanguage", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getHostLanguageChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getHostLanguage()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getHostLanguageChannel.setMessageHandler(nil)
    }
    let saveToGroupIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.watermeter.SaveToGroupIdSwiftApi.saveToGroupId", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      saveToGroupIdChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let dataArg = args[0] as! FileToGroupID
        api.saveToGroupId(data: dataArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      saveToGroupIdChannel.setMessageHandler(nil)
    }
  }
}
