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

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

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

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

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

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

  // Methods
  @inline(__always)
  public final func schedule(id: Double, delayMs: Double, kind: std.string, intervalMs: Double, group: std.string, driftPolicy: std.string, maxRuns: Double, correlationToken: Double, retryMaxAttempts: Double, retryInitialBackoffMs: Double, cancellationToken: std.string, tagMask: Double, policyProfile: std.string, callback: bridge.Func_void_double) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.schedule(id: id, delayMs: delayMs, kind: String(kind), intervalMs: intervalMs, group: String(group), driftPolicy: String(driftPolicy), maxRuns: maxRuns, correlationToken: correlationToken, retryMaxAttempts: retryMaxAttempts, retryInitialBackoffMs: retryInitialBackoffMs, cancellationToken: String(cancellationToken), tagMask: tagMask, policyProfile: String(policyProfile), callback: { () -> (Double) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_double(callback)
        return { (__id: Double) -> Void in
          __wrappedFunction.call(__id)
        }
      }())
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func cancel(id: Double) -> bridge.Result_void_ {
    do {
      try self.__implementation.cancel(id: id)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func pauseGroup(group: std.string) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.pauseGroup(group: String(group))
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func resumeGroup(group: std.string) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.resumeGroup(group: String(group))
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func cancelGroup(group: std.string) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.cancelGroup(group: String(group))
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func listActiveTimerIds() -> bridge.Result_std__vector_double__ {
    do {
      let __result = try self.__implementation.listActiveTimerIds()
      let __resultCpp = { () -> bridge.std__vector_double_ in
        var __vector = bridge.create_std__vector_double_(__result.count)
        for __item in __result {
          __vector.push_back(__item)
        }
        return __vector
      }()
      return bridge.create_Result_std__vector_double__(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__vector_double__(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func getStatsJson() -> bridge.Result_std__string_ {
    do {
      let __result = try self.__implementation.getStatsJson()
      let __resultCpp = std.string(__result)
      return bridge.create_Result_std__string_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__string_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func getPersistWireJson() -> bridge.Result_std__string_ {
    do {
      let __result = try self.__implementation.getPersistWireJson()
      let __resultCpp = std.string(__result)
      return bridge.create_Result_std__string_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_std__string_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func restorePersistWireJson(wireJson: std.string) -> bridge.Result_void_ {
    do {
      try self.__implementation.restorePersistWireJson(wireJson: String(wireJson))
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func setTimeout(id: Double, duration: Double, callback: bridge.Func_void_double) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.setTimeout(id: id, duration: duration, callback: { () -> (Double) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_double(callback)
        return { (__id: Double) -> Void in
          __wrappedFunction.call(__id)
        }
      }())
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func clearTimeout(id: Double) -> bridge.Result_void_ {
    do {
      try self.__implementation.clearTimeout(id: id)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func setInterval(id: Double, interval: Double, callback: bridge.Func_void_double) -> bridge.Result_double_ {
    do {
      let __result = try self.__implementation.setInterval(id: id, interval: interval, callback: { () -> (Double) -> Void in
        let __wrappedFunction = bridge.wrap_Func_void_double(callback)
        return { (__id: Double) -> Void in
          __wrappedFunction.call(__id)
        }
      }())
      let __resultCpp = __result
      return bridge.create_Result_double_(__resultCpp)
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_double_(__exceptionPtr)
    }
  }
  
  @inline(__always)
  public final func clearInterval(id: Double) -> bridge.Result_void_ {
    do {
      try self.__implementation.clearInterval(id: id)
      return bridge.create_Result_void_()
    } catch (let __error) {
      let __exceptionPtr = __error.toCpp()
      return bridge.create_Result_void_(__exceptionPtr)
    }
  }
}
