///
/// HybridDepthSpec_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 HybridDepthSpec 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 HybridDepthSpec_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 `HybridDepthSpec` Swift protocol.
   */
  private var __implementation: any HybridDepthSpec

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

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

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

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

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

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

  

  /**
   * 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 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: HybridDepthSpec_cxx) -> Bool {
    return self.__implementation === other.__implementation
  }

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

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

  // Properties
  public final var orientation: Int32 {
    @inline(__always)
    get {
      return self.__implementation.orientation.rawValue
    }
  }
  
  public final var isMirrored: Bool {
    @inline(__always)
    get {
      return self.__implementation.isMirrored
    }
  }
  
  public final var timestamp: Double {
    @inline(__always)
    get {
      return self.__implementation.timestamp
    }
  }
  
  public final var width: Double {
    @inline(__always)
    get {
      return self.__implementation.width
    }
  }
  
  public final var height: Double {
    @inline(__always)
    get {
      return self.__implementation.height
    }
  }
  
  public final var bytesPerRow: Double {
    @inline(__always)
    get {
      return self.__implementation.bytesPerRow
    }
  }
  
  public final var pixelFormat: Int32 {
    @inline(__always)
    get {
      return self.__implementation.pixelFormat.rawValue
    }
  }
  
  public final var isValid: Bool {
    @inline(__always)
    get {
      return self.__implementation.isValid
    }
  }
  
  public final var isDepthDataFiltered: Bool {
    @inline(__always)
    get {
      return self.__implementation.isDepthDataFiltered
    }
  }
  
  public final var depthDataAccuracy: Int32 {
    @inline(__always)
    get {
      return self.__implementation.depthDataAccuracy.rawValue
    }
  }
  
  public final var depthDataQuality: Int32 {
    @inline(__always)
    get {
      return self.__implementation.depthDataQuality.rawValue
    }
  }
  
  public final var availableDepthPixelFormats: bridge.std__vector_DepthPixelFormat_ {
    @inline(__always)
    get {
      return { () -> bridge.std__vector_DepthPixelFormat_ in
        var __vector = bridge.create_std__vector_DepthPixelFormat_(self.__implementation.availableDepthPixelFormats.count)
        for __item in self.__implementation.availableDepthPixelFormats {
          __vector.push_back(__item)
        }
        return __vector
      }()
    }
  }
  
  public final var cameraCalibrationData: bridge.std__optional_std__shared_ptr_HybridCameraCalibrationDataSpec__ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__shared_ptr_HybridCameraCalibrationDataSpec__ in
        if let __unwrappedValue = self.__implementation.cameraCalibrationData {
          return bridge.create_std__optional_std__shared_ptr_HybridCameraCalibrationDataSpec__({ () -> bridge.std__shared_ptr_HybridCameraCalibrationDataSpec_ in
            let __cxxWrapped = __unwrappedValue.getCxxWrapper()
            return __cxxWrapped.getCxxPart()
          }())
        } else {
          return .init()
        }
      }()
    }
  }

  // Methods
  @inline(__always)
  public final func getDepthData() -> bridge.Result_std__shared_ptr_ArrayBuffer__ {
    do {
      let __result = try self.__implementation.getDepthData()
      let __resultCpp = __result.getArrayBuffer()
      return bridge.create_Result_std__shared_ptr_ArrayBuffer__(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_ArrayBuffer__(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func getNativeBuffer() -> bridge.Result_NativeBuffer_ {
    do {
      let __result = try self.__implementation.getNativeBuffer()
      let __resultCpp = __result
      return bridge.create_Result_NativeBuffer_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_NativeBuffer_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func rotate(orientation: Int32, isMirrored: Bool) -> bridge.Result_std__shared_ptr_HybridDepthSpec__ {
    do {
      let __result = try self.__implementation.rotate(orientation: margelo.nitro.camera.CameraOrientation(rawValue: orientation)!, isMirrored: isMirrored)
      let __resultCpp = { () -> bridge.std__shared_ptr_HybridDepthSpec_ in
        let __cxxWrapped = __result.getCxxWrapper()
        return __cxxWrapped.getCxxPart()
      }()
      return bridge.create_Result_std__shared_ptr_HybridDepthSpec__(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_HybridDepthSpec__(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func rotateAsync(orientation: Int32, isMirrored: Bool) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____ {
    do {
      let __result = try self.__implementation.rotateAsync(orientation: margelo.nitro.camera.CameraOrientation(rawValue: orientation)!, isMirrored: isMirrored)
      let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___ in
        let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___()
        let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___(__promise)
        __result
          .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_HybridDepthSpec_ in
              let __cxxWrapped = __result.getCxxWrapper()
              return __cxxWrapped.getCxxPart()
            }()) })
          .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
        return __promise
      }()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func convert(pixelFormat: Int32) -> bridge.Result_std__shared_ptr_HybridDepthSpec__ {
    do {
      let __result = try self.__implementation.convert(pixelFormat: margelo.nitro.camera.DepthPixelFormat(rawValue: pixelFormat)!)
      let __resultCpp = { () -> bridge.std__shared_ptr_HybridDepthSpec_ in
        let __cxxWrapped = __result.getCxxWrapper()
        return __cxxWrapped.getCxxPart()
      }()
      return bridge.create_Result_std__shared_ptr_HybridDepthSpec__(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_HybridDepthSpec__(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func convertAsync(pixelFormat: Int32) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____ {
    do {
      let __result = try self.__implementation.convertAsync(pixelFormat: margelo.nitro.camera.DepthPixelFormat(rawValue: pixelFormat)!)
      let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___ in
        let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___()
        let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec___(__promise)
        __result
          .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_HybridDepthSpec_ in
              let __cxxWrapped = __result.getCxxWrapper()
              return __cxxWrapped.getCxxPart()
            }()) })
          .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
        return __promise
      }()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridDepthSpec____(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func convertCameraPointToDepthPoint(cameraPoint: Point) -> bridge.Result_Point_ {
    do {
      let __result = try self.__implementation.convertCameraPointToDepthPoint(cameraPoint: cameraPoint)
      let __resultCpp = __result
      return bridge.create_Result_Point_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_Point_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func convertDepthPointToCameraPoint(depthPoint: Point) -> bridge.Result_Point_ {
    do {
      let __result = try self.__implementation.convertDepthPointToCameraPoint(depthPoint: depthPoint)
      let __resultCpp = __result
      return bridge.create_Result_Point_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_Point_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func toFrame() -> bridge.Result_std__shared_ptr_HybridFrameSpec__ {
    do {
      let __result = try self.__implementation.toFrame()
      let __resultCpp = { () -> bridge.std__shared_ptr_HybridFrameSpec_ in
        let __cxxWrapped = __result.getCxxWrapper()
        return __cxxWrapped.getCxxPart()
      }()
      return bridge.create_Result_std__shared_ptr_HybridFrameSpec__(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_HybridFrameSpec__(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func toFrameAsync() -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec____ {
    do {
      let __result = try self.__implementation.toFrameAsync()
      let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec___ in
        let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec___()
        let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec___(__promise)
        __result
          .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_HybridFrameSpec_ in
              let __cxxWrapped = __result.getCxxWrapper()
              return __cxxWrapped.getCxxPart()
            }()) })
          .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
        return __promise
      }()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec____(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridFrameSpec____(__exceptionPtr)
    }
  }
}
