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

import Foundation
import NitroModules

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

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

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

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

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

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

  // Properties
  public final var player: bridge.std__optional_std__shared_ptr_HybridVideoPlayerSpec__ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__shared_ptr_HybridVideoPlayerSpec__ in
        if let __unwrappedValue = self.__implementation.player {
          return bridge.create_std__optional_std__shared_ptr_HybridVideoPlayerSpec__({ () -> bridge.std__shared_ptr_HybridVideoPlayerSpec_ in
            let __cxxWrapped = __unwrappedValue.getCxxWrapper()
            return __cxxWrapped.getCxxPart()
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.player = { () -> (any HybridVideoPlayerSpec)? in
        if let __unwrapped = newValue.value {
          return { () -> HybridVideoPlayerSpec in
            let __unsafePointer = bridge.get_std__shared_ptr_HybridVideoPlayerSpec_(__unwrapped)
            let __instance = HybridVideoPlayerSpec_cxx.fromUnsafe(__unsafePointer)
            return __instance.getHybridVideoPlayerSpec()
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var controls: Bool {
    @inline(__always)
    get {
      return self.__implementation.controls
    }
    @inline(__always)
    set {
      self.__implementation.controls = newValue
    }
  }
  
  public final var pictureInPicture: Bool {
    @inline(__always)
    get {
      return self.__implementation.pictureInPicture
    }
    @inline(__always)
    set {
      self.__implementation.pictureInPicture = newValue
    }
  }
  
  public final var autoEnterPictureInPicture: Bool {
    @inline(__always)
    get {
      return self.__implementation.autoEnterPictureInPicture
    }
    @inline(__always)
    set {
      self.__implementation.autoEnterPictureInPicture = newValue
    }
  }
  
  public final var resizeMode: Int32 {
    @inline(__always)
    get {
      return self.__implementation.resizeMode.rawValue
    }
    @inline(__always)
    set {
      self.__implementation.resizeMode = margelo.nitro.video.ResizeMode(rawValue: newValue)!
    }
  }
  
  public final var keepScreenAwake: Bool {
    @inline(__always)
    get {
      return self.__implementation.keepScreenAwake
    }
    @inline(__always)
    set {
      self.__implementation.keepScreenAwake = newValue
    }
  }
  
  public final var onPictureInPictureChange: bridge.std__optional_std__function_void_bool____isInPictureInPicture______ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void_bool____isInPictureInPicture______ in
        if let __unwrappedValue = self.__implementation.onPictureInPictureChange {
          return bridge.create_std__optional_std__function_void_bool____isInPictureInPicture______({ () -> bridge.Func_void_bool in
            let __closureWrapper = Func_void_bool(__unwrappedValue)
            return bridge.create_Func_void_bool(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onPictureInPictureChange = { () -> ((_ isInPictureInPicture: Bool) -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> (Bool) -> Void in
            let __wrappedFunction = bridge.wrap_Func_void_bool(__unwrapped)
            return { (__isInPictureInPicture: Bool) -> Void in
              __wrappedFunction.call(__isInPictureInPicture)
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var onFullscreenChange: bridge.std__optional_std__function_void_bool____fullscreen______ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void_bool____fullscreen______ in
        if let __unwrappedValue = self.__implementation.onFullscreenChange {
          return bridge.create_std__optional_std__function_void_bool____fullscreen______({ () -> bridge.Func_void_bool in
            let __closureWrapper = Func_void_bool(__unwrappedValue)
            return bridge.create_Func_void_bool(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onFullscreenChange = { () -> ((_ fullscreen: Bool) -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> (Bool) -> Void in
            let __wrappedFunction = bridge.wrap_Func_void_bool(__unwrapped)
            return { (__fullscreen: Bool) -> Void in
              __wrappedFunction.call(__fullscreen)
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var willEnterFullscreen: bridge.std__optional_std__function_void____ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void____ in
        if let __unwrappedValue = self.__implementation.willEnterFullscreen {
          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.willEnterFullscreen = { () -> (() -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> () -> Void in
            let __wrappedFunction = bridge.wrap_Func_void(__unwrapped)
            return { () -> Void in
              __wrappedFunction.call()
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var willExitFullscreen: bridge.std__optional_std__function_void____ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void____ in
        if let __unwrappedValue = self.__implementation.willExitFullscreen {
          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.willExitFullscreen = { () -> (() -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> () -> Void in
            let __wrappedFunction = bridge.wrap_Func_void(__unwrapped)
            return { () -> Void in
              __wrappedFunction.call()
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var willEnterPictureInPicture: bridge.std__optional_std__function_void____ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void____ in
        if let __unwrappedValue = self.__implementation.willEnterPictureInPicture {
          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.willEnterPictureInPicture = { () -> (() -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> () -> Void in
            let __wrappedFunction = bridge.wrap_Func_void(__unwrapped)
            return { () -> Void in
              __wrappedFunction.call()
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var willExitPictureInPicture: bridge.std__optional_std__function_void____ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__function_void____ in
        if let __unwrappedValue = self.__implementation.willExitPictureInPicture {
          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.willExitPictureInPicture = { () -> (() -> Void)? in
        if let __unwrapped = newValue.value {
          return { () -> () -> Void in
            let __wrappedFunction = bridge.wrap_Func_void(__unwrapped)
            return { () -> Void in
              __wrappedFunction.call()
            }
          }()
        } else {
          return nil
        }
      }()
    }
  }

  // Methods
  @inline(__always)
  public final func enterFullscreen() -> bridge.Result_void_ {
    do {
      try self.__implementation.enterFullscreen()
      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 enterPictureInPicture() -> bridge.Result_void_ {
    do {
      try self.__implementation.enterPictureInPicture()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func exitPictureInPicture() -> bridge.Result_void_ {
    do {
      try self.__implementation.exitPictureInPicture()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func canEnterPictureInPicture() -> bridge.Result_bool_ {
    do {
      let __result = try self.__implementation.canEnterPictureInPicture()
      let __resultCpp = __result
      return bridge.create_Result_bool_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_bool_(__exceptionPtr)
    }
  }
}
