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

#pragma once

#include "HybridTorchSpec.hpp"

// Forward declaration of `HybridTorchSpec_cxx` to properly resolve imports.
namespace NitroTorch { class HybridTorchSpec_cxx; }



#include <functional>
#include <optional>
#include <NitroModules/Promise.hpp>

#include "NitroTorch-Swift-Cxx-Umbrella.hpp"

namespace margelo::nitro::nitrotorch {

  /**
   * The C++ part of HybridTorchSpec_cxx.swift.
   *
   * HybridTorchSpecSwift (C++) accesses HybridTorchSpec_cxx (Swift), and might
   * contain some additional bridging code for C++ <> Swift interop.
   *
   * Since this obviously introduces an overhead, I hope at some point in
   * the future, HybridTorchSpec_cxx can directly inherit from the C++ class HybridTorchSpec
   * to simplify the whole structure and memory management.
   */
  class HybridTorchSpecSwift: public virtual HybridTorchSpec {
  public:
    // Constructor from a Swift instance
    explicit HybridTorchSpecSwift(const NitroTorch::HybridTorchSpec_cxx& swiftPart):
      HybridObject(HybridTorchSpec::TAG),
      _swiftPart(swiftPart) { }

  public:
    // Get the Swift part
    inline NitroTorch::HybridTorchSpec_cxx& getSwiftPart() noexcept {
      return _swiftPart;
    }

  public:
    inline size_t getExternalMemorySize() noexcept override {
      return _swiftPart.getMemorySize();
    }
    void dispose() noexcept override {
      _swiftPart.dispose();
    }

  public:
    // Properties
    inline std::optional<std::function<void(bool /* state */)>> getOnStateChanged() noexcept override {
      auto __result = _swiftPart.getOnStateChanged();
      return __result;
    }
    inline void setOnStateChanged(const std::optional<std::function<void(bool /* state */)>>& onStateChanged) noexcept override {
      _swiftPart.setOnStateChanged(onStateChanged);
    }
    inline std::optional<std::function<void(std::optional<double> /* level */)>> getOnLevelChanged() noexcept override {
      auto __result = _swiftPart.getOnLevelChanged();
      return __result;
    }
    inline void setOnLevelChanged(const std::optional<std::function<void(std::optional<double> /* level */)>>& onLevelChanged) noexcept override {
      _swiftPart.setOnLevelChanged(onLevelChanged);
    }

  public:
    // Methods
    inline std::shared_ptr<Promise<void>> on() override {
      auto __result = _swiftPart.on();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> off() override {
      auto __result = _swiftPart.off();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> toggle() override {
      auto __result = _swiftPart.toggle();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> setLevel(double level) override {
      auto __result = _swiftPart.setLevel(std::forward<decltype(level)>(level));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::optional<double> getMaxLevel(std::optional<bool> dynamic) override {
      auto __result = _swiftPart.getMaxLevel(dynamic);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }

  private:
    NitroTorch::HybridTorchSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::nitrotorch
