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

import NitroModules

/**
 * A class implementation that bridges HybridCameraDepthFrameOutputSpec over to C++.
 * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
 *
 * Also, some Swift types need to be bridged with special handling:
 * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
 * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
 * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
 */
open class HybridCameraDepthFrameOutputSpec_cxx : HybridCameraOutputSpec_cxx {
  /**
   * The Swift <> C++ bridge's namespace (`margelo::nitro::camera::bridge::swift`)
   * from `VisionCamera-Swift-Cxx-Bridge.hpp`.
   * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
   */
  public typealias bridge = margelo.nitro.camera.bridge.swift

  /**
   * Holds an instance of the `HybridCameraDepthFrameOutputSpec` Swift protocol.
   */
  private var __implementation: any HybridCameraDepthFrameOutputSpec

  /**
   * Holds a weak pointer to the C++ class that wraps the Swift class.
   */
  private var __cxxPart: bridge.std__weak_ptr_HybridCameraDepthFrameOutputSpec_

  /**
   * Create a new `HybridCameraDepthFrameOutputSpec_cxx` that wraps the given `HybridCameraDepthFrameOutputSpec`.
   * All properties and methods bridge to C++ types.
   */
  public init(_ implementation: any HybridCameraDepthFrameOutputSpec) {
    self.__implementation = implementation
    self.__cxxPart = .init()
    super.init(implementation)
  }

  /**
   * Get the actual `HybridCameraDepthFrameOutputSpec` instance this class wraps.
   */
  @inline(__always)
  public func getHybridCameraDepthFrameOutputSpec() -> any HybridCameraDepthFrameOutputSpec {
    return __implementation
  }

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

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

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridCameraDepthFrameOutputSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridCameraDepthFrameOutputSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridCameraDepthFrameOutputSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridCameraDepthFrameOutputSpec_(newCxxPart)
      return newCxxPart
    }
  }

  public override func getCxxPart() -> bridge.std__shared_ptr_HybridCameraOutputSpec_ {
    let ownCxxPart: bridge.std__shared_ptr_HybridCameraDepthFrameOutputSpec_ = getCxxPart()
    return bridge.upcast_CameraDepthFrameOutput_to_CameraOutput(ownCxxPart)
  }

  /**
   * Get the memory size of the Swift class (plus size of any other allocations)
   * so the JS VM can properly track it and garbage-collect the JS object if needed.
   */
  @inline(__always)
  public override var memorySize: Int {
    return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
  }

  /**
   * Compares this object with the given [other] object for reference equality.
   */
  @inline(__always)
  public func equals(other: HybridCameraDepthFrameOutputSpec_cxx) -> Bool {
    return self.__implementation === other.__implementation
  }

  /**
   * Call dispose() on the Swift class.
   * This _may_ be called manually from JS.
   */
  @inline(__always)
  public override func dispose() {
    self.__implementation.dispose()
  }

  /**
   * Call toString() on the Swift class.
   */
  @inline(__always)
  public override func toString() -> String {
    return self.__implementation.toString()
  }

  // Properties
  public final var thread: bridge.std__shared_ptr_HybridNativeThreadSpec_ {
    @inline(__always)
    get {
      return { () -> bridge.std__shared_ptr_HybridNativeThreadSpec_ in
        let __cxxWrapped = self.__implementation.thread.getCxxWrapper()
        return __cxxWrapped.getCxxPart()
      }()
    }
  }

  // Methods
  @inline(__always)
  public final func setOnDepthFrameCallback(onDepthFrame: bridge.std__optional_std__function_bool_const_std__shared_ptr_HybridDepthSpec______depth______) -> bridge.Result_void_ {
    do {
      try self.__implementation.setOnDepthFrameCallback(onDepthFrame: { () -> ((_ depth: (any HybridDepthSpec)) -> Bool)? in
        if bridge.has_value_std__optional_std__function_bool_const_std__shared_ptr_HybridDepthSpec______depth______(onDepthFrame) {
          let __unwrapped = bridge.get_std__optional_std__function_bool_const_std__shared_ptr_HybridDepthSpec______depth______(onDepthFrame)
          return { () -> ((any HybridDepthSpec)) -> Bool in
            let __wrappedFunction = bridge.wrap_Func_bool_std__shared_ptr_HybridDepthSpec_(__unwrapped)
            return { (__depth: (any HybridDepthSpec)) -> Bool in
              let __result = __wrappedFunction.call({ () -> bridge.std__shared_ptr_HybridDepthSpec_ in
                let __cxxWrapped = __depth.getCxxWrapper()
                return __cxxWrapped.getCxxPart()
              }())
              return __result
            }
          }()
        } else {
          return nil
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func setOnDepthFrameDroppedCallback(onDepthFrameDropped: bridge.std__optional_std__function_void_FrameDroppedReason____reason______) -> bridge.Result_void_ {
    do {
      try self.__implementation.setOnDepthFrameDroppedCallback(onDepthFrameDropped: { () -> ((_ reason: FrameDroppedReason) -> Void)? in
        if bridge.has_value_std__optional_std__function_void_FrameDroppedReason____reason______(onDepthFrameDropped) {
          let __unwrapped = bridge.get_std__optional_std__function_void_FrameDroppedReason____reason______(onDepthFrameDropped)
          return { () -> (FrameDroppedReason) -> Void in
            let __wrappedFunction = bridge.wrap_Func_void_FrameDroppedReason(__unwrapped)
            return { (__reason: FrameDroppedReason) -> Void in
              __wrappedFunction.call(__reason.rawValue)
            }
          }()
        } else {
          return nil
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
}
