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

import Foundation
import NitroModules

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

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

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

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

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

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridBlurViewSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridBlurViewSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridBlurViewSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridBlurViewSpec_(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: HybridBlurViewSpec_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 blurRadius: bridge.std__optional_double_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_double_ in
        if let __unwrappedValue = self.__implementation.blurRadius {
          return bridge.create_std__optional_double_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.blurRadius = newValue.value
    }
  }
  
  public final var cornerRadius: bridge.std__optional_double_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_double_ in
        if let __unwrappedValue = self.__implementation.cornerRadius {
          return bridge.create_std__optional_double_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.cornerRadius = newValue.value
    }
  }
  
  public final var blurRounds: bridge.std__optional_double_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_double_ in
        if let __unwrappedValue = self.__implementation.blurRounds {
          return bridge.create_std__optional_double_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.blurRounds = newValue.value
    }
  }
  
  public final var overlayColor: bridge.std__optional_std__string_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_std__string_ in
        if let __unwrappedValue = self.__implementation.overlayColor {
          return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.overlayColor = { () -> String? in
        if bridge.has_value_std__optional_std__string_(newValue) {
          let __unwrapped = bridge.get_std__optional_std__string_(newValue)
          return String(__unwrapped)
        } else {
          return nil
        }
      }()
    }
  }
  
  public final var downsampleFactor: bridge.std__optional_double_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_double_ in
        if let __unwrappedValue = self.__implementation.downsampleFactor {
          return bridge.create_std__optional_double_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.downsampleFactor = newValue.value
    }
  }

  // Methods
  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? RecyclableView else { return }
    recyclable.prepareForRecycle()
  }
}
