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

import Foundation
import NitroModules

/**
 * A class implementation that bridges HybridNitroVtoViewSpec 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 HybridNitroVtoViewSpec_cxx {
  /**
   * The Swift <> C++ bridge's namespace (`margelo::nitro::nitrovto::bridge::swift`)
   * from `NitroVto-Swift-Cxx-Bridge.hpp`.
   * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
   */
  public typealias bridge = margelo.nitro.nitrovto.bridge.swift

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

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

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

  /**
   * Get the actual `HybridNitroVtoViewSpec` instance this class wraps.
   */
  @inline(__always)
  public func getHybridNitroVtoViewSpec() -> any HybridNitroVtoViewSpec {
    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 `HybridNitroVtoViewSpec_cxx`.
   * The pointer has to be a retained opaque `Unmanaged<HybridNitroVtoViewSpec_cxx>`.
   * This removes one strong reference from the object!
   */
  public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNitroVtoViewSpec_cxx {
    return Unmanaged<HybridNitroVtoViewSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
  }

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridNitroVtoViewSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridNitroVtoViewSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridNitroVtoViewSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridNitroVtoViewSpec_(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
  }

  /**
   * 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 modelUrl: std.string {
    @inline(__always)
    get {
      return std.string(self.__implementation.modelUrl)
    }
    @inline(__always)
    set {
      self.__implementation.modelUrl = String(newValue)
    }
  }
  
  public final var isActive: Bool {
    @inline(__always)
    get {
      return self.__implementation.isActive
    }
    @inline(__always)
    set {
      self.__implementation.isActive = newValue
    }
  }
  
  public final var onModelLoaded: bridge.std__optional_std__function_void_const_std__string_____modelUrl______ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void_const_std__string_____modelUrl______ in
        if let __unwrappedValue = self.__implementation.onModelLoaded {
          return bridge.create_std__optional_std__function_void_const_std__string_____modelUrl______({ () -> bridge.Func_void_std__string in
            let __closureWrapper = Func_void_std__string(__unwrappedValue)
            return bridge.create_Func_void_std__string(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onModelLoaded = { () -> ((_ modelUrl: String) -> Void)? in
        if bridge.has_value_std__optional_std__function_void_const_std__string_____modelUrl______(newValue) {
          let __unwrapped = bridge.get_std__optional_std__function_void_const_std__string_____modelUrl______(newValue)
          return { () -> (String) -> Void in
            let __wrappedFunction = bridge.wrap_Func_void_std__string(__unwrapped)
            return { (__modelUrl: String) -> Void in
              __wrappedFunction.call(std.string(__modelUrl))
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var onFaceTracked: bridge.std__optional_std__function_void____ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void____ in
        if let __unwrappedValue = self.__implementation.onFaceTracked {
          return bridge.create_std__optional_std__function_void____({ () -> bridge.Func_void in
            let __closureWrapper = Func_void(__unwrappedValue)
            return bridge.create_Func_void(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onFaceTracked = { () -> (() -> Void)? in
        if bridge.has_value_std__optional_std__function_void____(newValue) {
          let __unwrapped = bridge.get_std__optional_std__function_void____(newValue)
          return { () -> () -> Void in
            let __wrappedFunction = bridge.wrap_Func_void(__unwrapped)
            return { () -> Void in
              __wrappedFunction.call()
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var onGlassesDisplayed: bridge.std__optional_std__function_void_const_std__string_____modelUrl______ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void_const_std__string_____modelUrl______ in
        if let __unwrappedValue = self.__implementation.onGlassesDisplayed {
          return bridge.create_std__optional_std__function_void_const_std__string_____modelUrl______({ () -> bridge.Func_void_std__string in
            let __closureWrapper = Func_void_std__string(__unwrappedValue)
            return bridge.create_Func_void_std__string(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onGlassesDisplayed = { () -> ((_ modelUrl: String) -> Void)? in
        if bridge.has_value_std__optional_std__function_void_const_std__string_____modelUrl______(newValue) {
          let __unwrapped = bridge.get_std__optional_std__function_void_const_std__string_____modelUrl______(newValue)
          return { () -> (String) -> Void in
            let __wrappedFunction = bridge.wrap_Func_void_std__string(__unwrapped)
            return { (__modelUrl: String) -> Void in
              __wrappedFunction.call(std.string(__modelUrl))
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var forwardOffset: bridge.std__optional_double_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_double_ in
        if let __unwrappedValue = self.__implementation.forwardOffset {
          return bridge.create_std__optional_double_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.forwardOffset = newValue.value
    }
  }
  
  public final var debug: bridge.std__optional_bool_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_bool_ in
        if let __unwrappedValue = self.__implementation.debug {
          return bridge.create_std__optional_bool_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.debug = { () -> Bool? in
        if bridge.has_value_std__optional_bool_(newValue) {
          let __unwrapped = bridge.get_std__optional_bool_(newValue)
          return __unwrapped
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var showNativeFPS: bridge.std__optional_bool_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_bool_ in
        if let __unwrappedValue = self.__implementation.showNativeFPS {
          return bridge.create_std__optional_bool_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.showNativeFPS = { () -> Bool? in
        if bridge.has_value_std__optional_bool_(newValue) {
          let __unwrapped = bridge.get_std__optional_bool_(newValue)
          return __unwrapped
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var isClipOn: Bool {
    @inline(__always)
    get {
      return self.__implementation.isClipOn
    }
    @inline(__always)
    set {
      self.__implementation.isClipOn = newValue
    }
  }

  // Methods
  @inline(__always)
  public final func hideGlasses() -> bridge.Result_void_ {
    do {
      try self.__implementation.hideGlasses()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func showGlasses() -> bridge.Result_void_ {
    do {
      try self.__implementation.showGlasses()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  public final func getView() -> UnsafeMutableRawPointer {
    return Unmanaged.passRetained(__implementation.view).toOpaque()
  }
  
  public final func beforeUpdate() {
    __implementation.beforeUpdate()
  }
  
  public final func afterUpdate() {
    __implementation.afterUpdate()
  }
}
