///
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

import NitroModules


/**
 * Wraps a Swift `(_ payload: OnGetLicensePayload) -> Promise<Promise<String>>` as a class.
 * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
 */
public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload {
  public typealias bridge = margelo.nitro.video.bridge.swift

  private let closure: (_ payload: OnGetLicensePayload) -> Promise<Promise<String>>

  public init(_ closure: @escaping (_ payload: OnGetLicensePayload) -> Promise<Promise<String>>) {
    self.closure = closure
  }

  @inline(__always)
  public func call(payload: OnGetLicensePayload) -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__string____ {
    let __result: Promise<Promise<String>> = self.closure(payload)
    return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__string____ in
      let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string____()
      let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string____(__promise)
      __result
        .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_std__string__ in
            let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
            let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
            __result
              .then({ __result in __promiseHolder.resolve(std.string(__result)) })
              .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
            return __promise
          }()) })
        .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
      return __promise
    }()
  }

  /**
   * Casts this instance to a retained unsafe raw pointer.
   * This acquires one additional strong reference on the object!
   */
  @inline(__always)
  public func toUnsafe() -> UnsafeMutableRawPointer {
    return Unmanaged.passRetained(self).toOpaque()
  }

  /**
   * Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload`.
   * The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload>`.
   * This removes one strong reference from the object!
   */
  @inline(__always)
  public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload {
    return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload>.fromOpaque(pointer).takeRetainedValue()
  }
}
