PlatformApi.swift 13.2 KB
// // Copyright 2013 The Flutter Authors. All rights reserved.
// Autogenerated from Pigeon (v25.5.0), 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)",
    "\(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?
}

func deepEqualsPlatformApi(_ 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 is (Void, Void):
    return true

  case let (cleanLhsHashable, cleanRhsHashable) as (AnyHashable, AnyHashable):
    return cleanLhsHashable == cleanRhsHashable

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

  case let (cleanLhsDictionary, cleanRhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]):
    guard cleanLhsDictionary.count == cleanRhsDictionary.count else { return false }
    for (key, cleanLhsValue) in cleanLhsDictionary {
      guard cleanRhsDictionary.index(forKey: key) != nil else { return false }
      if !deepEqualsPlatformApi(cleanLhsValue, cleanRhsDictionary[key]!) {
        return false
      }
    }
    return true

  default:
    // Any other type shouldn't be able to be used with pigeon. File an issue if you find this to be untrue.
    return false
  }
}

func deepHashPlatformApi(value: Any?, hasher: inout Hasher) {
  if let valueList = value as? [AnyHashable] {
     for item in valueList { deepHashPlatformApi(value: item, hasher: &hasher) }
     return
  }

  if let valueDict = value as? [AnyHashable: AnyHashable] {
    for key in valueDict.keys { 
      hasher.combine(key)
      deepHashPlatformApi(value: valueDict[key]!, hasher: &hasher)
    }
    return
  }

  if let hashableValue = value as? AnyHashable {
    hasher.combine(hashableValue.hashValue)
  }

  return hasher.combine(String(describing: value))
}

    

enum AppleProductPaymentErrorMsg: Int {
  case missingUUID = 0
  case productNotFound = 1
  case userCancelled = 2
  case failedVerification = 3
  case unknown = 4
}

/// Generated class from Pigeon that represents data sent in messages.
struct AppleSignInModel: Hashable {
  var userId: String
  var email: String? = nil
  var nickname: String? = nil
  var identityToken: String? = nil


  // swift-format-ignore: AlwaysUseLowerCamelCase
  static func fromList(_ pigeonVar_list: [Any?]) -> AppleSignInModel? {
    let userId = pigeonVar_list[0] as! String
    let email: String? = nilOrValue(pigeonVar_list[1])
    let nickname: String? = nilOrValue(pigeonVar_list[2])
    let identityToken: String? = nilOrValue(pigeonVar_list[3])

    return AppleSignInModel(
      userId: userId,
      email: email,
      nickname: nickname,
      identityToken: identityToken
    )
  }
  func toList() -> [Any?] {
    return [
      userId,
      email,
      nickname,
      identityToken,
    ]
  }
  static func == (lhs: AppleSignInModel, rhs: AppleSignInModel) -> Bool {
    return deepEqualsPlatformApi(lhs.toList(), rhs.toList())  }
  func hash(into hasher: inout Hasher) {
    deepHashPlatformApi(value: toList(), hasher: &hasher)
  }
}

/// Generated class from Pigeon that represents data sent in messages.
struct AppleProductInfo: Hashable {
  var productId: String
  var originPriceDescription: String
  var priceDescription: String? = nil
  var originPrice: Double
  var price: Double? = nil
  var isTrialPeriod: Bool


  // swift-format-ignore: AlwaysUseLowerCamelCase
  static func fromList(_ pigeonVar_list: [Any?]) -> AppleProductInfo? {
    let productId = pigeonVar_list[0] as! String
    let originPriceDescription = pigeonVar_list[1] as! String
    let priceDescription: String? = nilOrValue(pigeonVar_list[2])
    let originPrice = pigeonVar_list[3] as! Double
    let price: Double? = nilOrValue(pigeonVar_list[4])
    let isTrialPeriod = pigeonVar_list[5] as! Bool

    return AppleProductInfo(
      productId: productId,
      originPriceDescription: originPriceDescription,
      priceDescription: priceDescription,
      originPrice: originPrice,
      price: price,
      isTrialPeriod: isTrialPeriod
    )
  }
  func toList() -> [Any?] {
    return [
      productId,
      originPriceDescription,
      priceDescription,
      originPrice,
      price,
      isTrialPeriod,
    ]
  }
  static func == (lhs: AppleProductInfo, rhs: AppleProductInfo) -> Bool {
    return deepEqualsPlatformApi(lhs.toList(), rhs.toList())  }
  func hash(into hasher: inout Hasher) {
    deepHashPlatformApi(value: toList(), hasher: &hasher)
  }
}

/// Generated class from Pigeon that represents data sent in messages.
struct AppleProductPaymentResult: Hashable {
  var productId: String
  var appAccountToken: String? = nil
  var originalTransactionId: String? = nil
  var transactionId: String? = nil
  var success: Bool? = nil
  /// 错误描述:
  /// 和AppleProductPaymentErrorMsg匹配的flutter处理,
  /// 不匹配的则是StoreKit 直接给的错误描述,直接展示即可
  var errorMessage: String? = nil


  // swift-format-ignore: AlwaysUseLowerCamelCase
  static func fromList(_ pigeonVar_list: [Any?]) -> AppleProductPaymentResult? {
    let productId = pigeonVar_list[0] as! String
    let appAccountToken: String? = nilOrValue(pigeonVar_list[1])
    let originalTransactionId: String? = nilOrValue(pigeonVar_list[2])
    let transactionId: String? = nilOrValue(pigeonVar_list[3])
    let success: Bool? = nilOrValue(pigeonVar_list[4])
    let errorMessage: String? = nilOrValue(pigeonVar_list[5])

    return AppleProductPaymentResult(
      productId: productId,
      appAccountToken: appAccountToken,
      originalTransactionId: originalTransactionId,
      transactionId: transactionId,
      success: success,
      errorMessage: errorMessage
    )
  }
  func toList() -> [Any?] {
    return [
      productId,
      appAccountToken,
      originalTransactionId,
      transactionId,
      success,
      errorMessage,
    ]
  }
  static func == (lhs: AppleProductPaymentResult, rhs: AppleProductPaymentResult) -> Bool {
    return deepEqualsPlatformApi(lhs.toList(), rhs.toList())  }
  func hash(into hasher: inout Hasher) {
    deepHashPlatformApi(value: toList(), hasher: &hasher)
  }
}

private class PlatformApiPigeonCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
    case 129:
      let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)
      if let enumResultAsInt = enumResultAsInt {
        return AppleProductPaymentErrorMsg(rawValue: enumResultAsInt)
      }
      return nil
    case 130:
      return AppleSignInModel.fromList(self.readValue() as! [Any?])
    case 131:
      return AppleProductInfo.fromList(self.readValue() as! [Any?])
    case 132:
      return AppleProductPaymentResult.fromList(self.readValue() as! [Any?])
    default:
      return super.readValue(ofType: type)
    }
  }
}

private class PlatformApiPigeonCodecWriter: FlutterStandardWriter {
  override func writeValue(_ value: Any) {
    if let value = value as? AppleProductPaymentErrorMsg {
      super.writeByte(129)
      super.writeValue(value.rawValue)
    } else if let value = value as? AppleSignInModel {
      super.writeByte(130)
      super.writeValue(value.toList())
    } else if let value = value as? AppleProductInfo {
      super.writeByte(131)
      super.writeValue(value.toList())
    } else if let value = value as? AppleProductPaymentResult {
      super.writeByte(132)
      super.writeValue(value.toList())
    } else {
      super.writeValue(value)
    }
  }
}

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

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

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


/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol PlatformHostApi {
  /// 返回完整的 User-Agent 字符串,由 native 侧组装:
  /// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
  func getFullUserAgent() throws -> String
  /// 请求苹果登录
  func requestAppleSignIn(completion: @escaping (Result<AppleSignInModel?, Error>) -> Void)
  /// 查询指定id的苹果商品
  func requestAppleProductInfo(productId: String, completion: @escaping (Result<AppleProductInfo?, Error>) -> Void)
  /// 从服务器下单后请求苹果支付
  func performApplePayment(productId: String, uuid: String, completion: @escaping (Result<AppleProductPaymentResult?, Error>) -> Void)
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class PlatformHostApiSetup {
  static var codec: FlutterStandardMessageCodec { PlatformApiPigeonCodec.shared }
  /// Sets up an instance of `PlatformHostApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PlatformHostApi?, messageChannelSuffix: String = "") {
    let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
    /// 返回完整的 User-Agent 字符串,由 native 侧组装:
    /// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
    let getFullUserAgentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getFullUserAgent\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      getFullUserAgentChannel.setMessageHandler { _, reply in
        do {
          let result = try api.getFullUserAgent()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      getFullUserAgentChannel.setMessageHandler(nil)
    }
    /// 请求苹果登录
    let requestAppleSignInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleSignIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      requestAppleSignInChannel.setMessageHandler { _, reply in
        api.requestAppleSignIn { result in
          switch result {
          case .success(let res):
            reply(wrapResult(res))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      requestAppleSignInChannel.setMessageHandler(nil)
    }
    /// 查询指定id的苹果商品
    let requestAppleProductInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleProductInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      requestAppleProductInfoChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let productIdArg = args[0] as! String
        api.requestAppleProductInfo(productId: productIdArg) { result in
          switch result {
          case .success(let res):
            reply(wrapResult(res))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      requestAppleProductInfoChannel.setMessageHandler(nil)
    }
    /// 从服务器下单后请求苹果支付
    let performApplePaymentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.performApplePayment\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      performApplePaymentChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let productIdArg = args[0] as! String
        let uuidArg = args[1] as! String
        api.performApplePayment(productId: productIdArg, uuid: uuidArg) { result in
          switch result {
          case .success(let res):
            reply(wrapResult(res))
          case .failure(let error):
            reply(wrapError(error))
          }
        }
      }
    } else {
      performApplePaymentChannel.setMessageHandler(nil)
    }
  }
}