///
/// HybridVideoViewSpec_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 HybridVideoViewSpec 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 HybridVideoViewSpec_cxx {
  /**
   * The Swift <> C++ bridge's namespace (`margelo::nitro::aviation::bridge::swift`)
   * from `Aviation-Swift-Cxx-Bridge.hpp`.
   * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
   */
  public typealias bridge = margelo.nitro.aviation.bridge.swift

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

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

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

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

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridVideoViewSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridVideoViewSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridVideoViewSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridVideoViewSpec_(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: HybridVideoViewSpec_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 resizeMode: Int32 {
    @inline(__always)
    get {
      return self.__implementation.resizeMode.rawValue
    }
    @inline(__always)
    set {
      self.__implementation.resizeMode = margelo.nitro.aviation.ResizeMode(rawValue: newValue)!
    }
  }
  
  public final var pipEnabled: Bool {
    @inline(__always)
    get {
      return self.__implementation.pipEnabled
    }
    @inline(__always)
    set {
      self.__implementation.pipEnabled = newValue
    }
  }
  
  public final var playInBackground: Bool {
    @inline(__always)
    get {
      return self.__implementation.playInBackground
    }
    @inline(__always)
    set {
      self.__implementation.playInBackground = newValue
    }
  }
  
  public final var onPipStart: bridge.Func_void {
    @inline(__always)
    get {
      return { () -> bridge.Func_void in
        let __closureWrapper = Func_void(self.__implementation.onPipStart)
        return bridge.create_Func_void(__closureWrapper.toUnsafe())
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onPipStart = { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(newValue)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }()
    }
  }
  
  public final var onPipStop: bridge.Func_void {
    @inline(__always)
    get {
      return { () -> bridge.Func_void in
        let __closureWrapper = Func_void(self.__implementation.onPipStop)
        return bridge.create_Func_void(__closureWrapper.toUnsafe())
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onPipStop = { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(newValue)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }()
    }
  }
  
  public final var surfaceType: Int32 {
    @inline(__always)
    get {
      return self.__implementation.surfaceType.rawValue
    }
    @inline(__always)
    set {
      self.__implementation.surfaceType = margelo.nitro.aviation.SurfaceType(rawValue: newValue)!
    }
  }
  
  public final var onFullscreenEnter: bridge.Func_void {
    @inline(__always)
    get {
      return { () -> bridge.Func_void in
        let __closureWrapper = Func_void(self.__implementation.onFullscreenEnter)
        return bridge.create_Func_void(__closureWrapper.toUnsafe())
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onFullscreenEnter = { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(newValue)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }()
    }
  }
  
  public final var onFullscreenExit: bridge.Func_void {
    @inline(__always)
    get {
      return { () -> bridge.Func_void in
        let __closureWrapper = Func_void(self.__implementation.onFullscreenExit)
        return bridge.create_Func_void(__closureWrapper.toUnsafe())
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onFullscreenExit = { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(newValue)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }()
    }
  }
  
  public final var selectedVideoTrack: VideoTrackSelection {
    @inline(__always)
    get {
      return self.__implementation.selectedVideoTrack
    }
    @inline(__always)
    set {
      self.__implementation.selectedVideoTrack = newValue
    }
  }
  
  public final var selectedSubtitleTrack: SubtitleTrackSelection {
    @inline(__always)
    get {
      return self.__implementation.selectedSubtitleTrack
    }
    @inline(__always)
    set {
      self.__implementation.selectedSubtitleTrack = newValue
    }
  }
  
  public final var selectedAudioTrack: AudioTrackSelection {
    @inline(__always)
    get {
      return self.__implementation.selectedAudioTrack
    }
    @inline(__always)
    set {
      self.__implementation.selectedAudioTrack = newValue
    }
  }
  
  public final var adTagUrl: std.string {
    @inline(__always)
    get {
      return std.string(self.__implementation.adTagUrl)
    }
    @inline(__always)
    set {
      self.__implementation.adTagUrl = String(newValue)
    }
  }
  
  public final var source: VideoSource {
    @inline(__always)
    get {
      return self.__implementation.source
    }
    @inline(__always)
    set {
      self.__implementation.source = newValue
    }
  }
  
  public final var autoPlay: Bool {
    @inline(__always)
    get {
      return self.__implementation.autoPlay
    }
    @inline(__always)
    set {
      self.__implementation.autoPlay = newValue
    }
  }

  // Methods
  @inline(__always)
  public final func attachEngine(engine: bridge.std__shared_ptr_HybridPlaybackEngineSpec_) -> bridge.Result_void_ {
    do {
      try self.__implementation.attachEngine(engine: { () -> any HybridPlaybackEngineSpec in
        let __unsafePointer = bridge.get_std__shared_ptr_HybridPlaybackEngineSpec_(engine)
        let __instance = HybridPlaybackEngineSpec_cxx.fromUnsafe(__unsafePointer)
        return __instance.getHybridPlaybackEngineSpec()
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func detachEngine() -> bridge.Result_void_ {
    do {
      try self.__implementation.detachEngine()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func startPictureInPicture() -> bridge.Result_void_ {
    do {
      try self.__implementation.startPictureInPicture()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func stopPictureInPicture() -> bridge.Result_void_ {
    do {
      try self.__implementation.stopPictureInPicture()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func enterFullscreen(config: bridge.std__optional_FullscreenConfig_) -> bridge.Result_void_ {
    do {
      try self.__implementation.enterFullscreen(config: config.value)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func exitFullscreen() -> bridge.Result_void_ {
    do {
      try self.__implementation.exitFullscreen()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func isFullscreen() -> bridge.Result_bool_ {
    do {
      let __result = try self.__implementation.isFullscreen()
      let __resultCpp = __result
      return bridge.create_Result_bool_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_bool_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func enterNativeFullscreen() -> bridge.Result_void_ {
    do {
      try self.__implementation.enterNativeFullscreen()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func applyVideoTrack(selection: VideoTrackSelection) -> bridge.Result_void_ {
    do {
      try self.__implementation.applyVideoTrack(selection: selection)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func applySubtitleTrack(selection: SubtitleTrackSelection) -> bridge.Result_void_ {
    do {
      try self.__implementation.applySubtitleTrack(selection: selection)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func applyAudioTrack(selection: AudioTrackSelection) -> bridge.Result_void_ {
    do {
      try self.__implementation.applyAudioTrack(selection: selection)
      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()
  }
  
  public final func maybePrepareForRecycle() {
    guard let recyclable = __implementation as? any RecyclableView else { return }
    recyclable.prepareForRecycle()
  }
}
