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

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

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

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

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

  /**
   * Gets (or creates) the C++ part of this Hybrid Object.
   * The C++ part is a `std::shared_ptr<HybridGoogleSignInButtonSpec>`.
   */
  public func getCxxPart() -> bridge.std__shared_ptr_HybridGoogleSignInButtonSpec_ {
    let cachedCxxPart = self.__cxxPart.lock()
    if Bool(fromCxx: cachedCxxPart) {
      return cachedCxxPart
    } else {
      let newCxxPart = bridge.create_std__shared_ptr_HybridGoogleSignInButtonSpec_(self.toUnsafe())
      __cxxPart = bridge.weakify_std__shared_ptr_HybridGoogleSignInButtonSpec_(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: HybridGoogleSignInButtonSpec_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 colorScheme: Int32 {
    @inline(__always)
    get {
      return self.__implementation.colorScheme.rawValue
    }
    @inline(__always)
    set {
      self.__implementation.colorScheme = margelo.nitro.nitrogooglesignin.GoogleSignInButtonColorScheme(rawValue: newValue)!
    }
  }
  
  public final var size: Int32 {
    @inline(__always)
    get {
      return self.__implementation.size.rawValue
    }
    @inline(__always)
    set {
      self.__implementation.size = margelo.nitro.nitrogooglesignin.GoogleSignInButtonNativeSize(rawValue: newValue)!
    }
  }
  
  public final var disabled: Bool {
    @inline(__always)
    get {
      return self.__implementation.disabled
    }
    @inline(__always)
    set {
      self.__implementation.disabled = newValue
    }
  }
  
  public final var contentAlignment: bridge.std__optional_GoogleSignInButtonContentAlignment_ {
    @inline(__always)
    get {
      return { () -> bridge.std__optional_GoogleSignInButtonContentAlignment_ in
        if let __unwrappedValue = self.__implementation.contentAlignment {
          return bridge.create_std__optional_GoogleSignInButtonContentAlignment_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
    @inline(__always)
    set {
      self.__implementation.contentAlignment = newValue.value
    }
  }
  
  public final var onPress: bridge.Func_void {
    @inline(__always)
    get {
      return { () -> bridge.Func_void in
        let __closureWrapper = Func_void(self.__implementation.onPress)
        return bridge.create_Func_void(__closureWrapper.toUnsafe())
      }()
    }
    @inline(__always)
    set {
      self.__implementation.onPress = { () -> () -> Void in
        let __wrappedFunction = bridge.wrap_Func_void(newValue)
        return { () -> Void in
          __wrappedFunction.call()
        }
      }()
    }
  }

  // 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? any RecyclableView else { return }
    recyclable.prepareForRecycle()
  }
  
  public final func onDropView() {
    __implementation.onDropView()
  }
}
