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

import NitroModules

/**
 * Wraps a Swift `(_ level: PTLocationAccess) -> Promise<Bool>` 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_bool___PTLocationAccess {
  public typealias bridge = margelo.nitro.espprovtoolkit.bridge.swift

  private let closure: (_ level: PTLocationAccess) -> Promise<Bool>

  public init(_ closure: @escaping (_ level: PTLocationAccess) -> Promise<Bool>) {
    self.closure = closure
  }

  @inline(__always)
  public func call(level: Int32) -> bridge.std__shared_ptr_Promise_bool__ {
    let __result: Promise<Bool> = self.closure(margelo.nitro.espprovtoolkit.PTLocationAccess(rawValue: level)!)
    return { () -> bridge.std__shared_ptr_Promise_bool__ in
      let __promise = bridge.create_std__shared_ptr_Promise_bool__()
      let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
      __result
        .then({ __result in __promiseHolder.resolve(__result) })
        .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_bool___PTLocationAccess`.
   * The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_bool___PTLocationAccess>`.
   * This removes one strong reference from the object!
   */
  @inline(__always)
  public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_bool___PTLocationAccess {
    return Unmanaged<Func_std__shared_ptr_Promise_bool___PTLocationAccess>.fromOpaque(pointer).takeRetainedValue()
  }
}
