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

#include "JHybridOneBarometerSpec.hpp"

// Forward declaration of `BarometerMeasurement` to properly resolve imports.
namespace margelo::nitro::one { struct BarometerMeasurement; }

#include <functional>
#include "JFunc_void.hpp"
#include <NitroModules/JNICallable.hpp>
#include "BarometerMeasurement.hpp"
#include "JFunc_void_BarometerMeasurement.hpp"
#include "JBarometerMeasurement.hpp"
#include <optional>

namespace margelo::nitro::one {

  std::shared_ptr<JHybridOneBarometerSpec> JHybridOneBarometerSpec::JavaPart::getJHybridOneBarometerSpec() {
    auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
    auto castHybridObject = std::dynamic_pointer_cast<JHybridOneBarometerSpec>(hybridObject);
    if (castHybridObject == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to downcast JHybridObject to JHybridOneBarometerSpec!");
    }
    return castHybridObject;
  }

  jni::local_ref<JHybridOneBarometerSpec::CxxPart::jhybriddata> JHybridOneBarometerSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
    return makeCxxInstance(jThis);
  }

  std::shared_ptr<JHybridObject> JHybridOneBarometerSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
    auto castJavaPart = jni::dynamic_ref_cast<JHybridOneBarometerSpec::JavaPart>(javaPart);
    if (castJavaPart == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridOneBarometerSpec::JavaPart!");
    }
    return std::make_shared<JHybridOneBarometerSpec>(castJavaPart);
  }

  void JHybridOneBarometerSpec::CxxPart::registerNatives() {
    registerHybrid({
      makeNativeMethod("initHybrid", JHybridOneBarometerSpec::CxxPart::initHybrid),
    });
  }

  // Properties
  

  // Methods
  bool JHybridOneBarometerSpec::isAvailable() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isAvailable");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  void JHybridOneBarometerSpec::setUpdateInterval(double intervalMs) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* intervalMs */)>("setUpdateInterval");
    method(_javaPart, intervalMs);
  }
  std::function<void()> JHybridOneBarometerSpec::addListener(const std::function<void(const BarometerMeasurement& /* event */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_BarometerMeasurement::javaobject> /* listener */)>("addListener_cxx");
    auto __result = method(_javaPart, JFunc_void_BarometerMeasurement_cxx::fromCpp(listener));
    return [&]() -> std::function<void()> {
      if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
        auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
        return downcast->cthis()->getFunction();
      } else {
        auto __resultRef = jni::make_global(__result);
        return JNICallable<JFunc_void, void()>(std::move(__resultRef));
      }
    }();
  }

} // namespace margelo::nitro::one
