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

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

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

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

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridAdsControllerSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridAdsControllerSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridAdsControllerSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridAdsControllerSpec_(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: HybridAdsControllerSpec_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 isPlayingAd: Bool {
    @inline(__always)
    get {
      return self.__implementation.isPlayingAd
    }
  }
  
  public final var currentAdBreakInfo: bridge.std__optional_AdBreakInfo_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_AdBreakInfo_ in
        if let __unwrappedValue = self.__implementation.currentAdBreakInfo {
          return bridge.create_std__optional_AdBreakInfo_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
  }
  
  public final var currentAdInfo: bridge.std__optional_AdInfo_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_AdInfo_ in
        if let __unwrappedValue = self.__implementation.currentAdInfo {
          return bridge.create_std__optional_AdInfo_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
  }

  // Methods
  @inline(__always)
  public final func configure(config: AdsConfig) -> bridge.Result_void_ {
    do {
      try self.__implementation.configure(config: config)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func setAdTagUrl(url: std.string) -> bridge.Result_void_ {
    do {
      try self.__implementation.setAdTagUrl(url: String(url))
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func addCuePoint(timeMs: Double, adTagUrl: std.string) -> bridge.Result_void_ {
    do {
      try self.__implementation.addCuePoint(timeMs: timeMs, adTagUrl: String(adTagUrl))
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func removeCuePoint(timeMs: Double) -> bridge.Result_void_ {
    do {
      try self.__implementation.removeCuePoint(timeMs: timeMs)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func clearCuePoints() -> bridge.Result_void_ {
    do {
      try self.__implementation.clearCuePoints()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func requestAd(adTagUrl: std.string) -> bridge.Result_std__shared_ptr_Promise_void___ {
    do {
      let __result = try self.__implementation.requestAd(adTagUrl: String(adTagUrl))
      let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
        let __promise = bridge.create_std__shared_ptr_Promise_void__()
        let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
        __result
          .then({ __result in __promiseHolder.resolve() })
          .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
        return __promise
      }()
      return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func skipAd() -> bridge.Result_void_ {
    do {
      try self.__implementation.skipAd()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func pauseAd() -> bridge.Result_void_ {
    do {
      try self.__implementation.pauseAd()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func resumeAd() -> bridge.Result_void_ {
    do {
      try self.__implementation.resumeAd()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdBreakStarted(callback: bridge.Func_void_AdBreakInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdBreakStarted(callback: { () -> (AdBreakInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdBreakInfo(callback)
        return { (__info: AdBreakInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdBreakEnded(callback: bridge.Func_void_AdBreakInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdBreakEnded(callback: { () -> (AdBreakInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdBreakInfo(callback)
        return { (__info: AdBreakInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdStarted(callback: bridge.Func_void_AdInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdStarted(callback: { () -> (AdInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdInfo(callback)
        return { (__info: AdInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdCompleted(callback: bridge.Func_void_AdInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdCompleted(callback: { () -> (AdInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdInfo(callback)
        return { (__info: AdInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdProgress(callback: bridge.Func_void_AdInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdProgress(callback: { () -> (AdInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdInfo(callback)
        return { (__info: AdInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdSkipped(callback: bridge.Func_void_AdInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdSkipped(callback: { () -> (AdInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdInfo(callback)
        return { (__info: AdInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdTapped(callback: bridge.Func_void_AdInfo) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdTapped(callback: { () -> (AdInfo) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_AdInfo(callback)
        return { (__info: AdInfo) -> Void in
          __wrappedFunction.call(__info)
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAdError(callback: bridge.Func_void_std__string) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAdError(callback: { () -> (String) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_std__string(callback)
        return { (__error: String) -> Void in
          __wrappedFunction.call(std.string(__error))
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func onAllAdsCompleted(callback: bridge.Func_void) -> bridge.Result_void_ {
    do {
      try self.__implementation.onAllAdsCompleted(callback: { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(callback)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }())
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func release() -> bridge.Result_void_ {
    do {
      try self.__implementation.release()
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
}
