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

#include "JHybridOrientationManagerSpec.hpp"

// Forward declaration of `OrientationSource` to properly resolve imports.
namespace margelo::nitro::camera { enum class OrientationSource; }
// Forward declaration of `CameraOrientation` to properly resolve imports.
namespace margelo::nitro::camera { enum class CameraOrientation; }

#include "OrientationSource.hpp"
#include "JOrientationSource.hpp"
#include "CameraOrientation.hpp"
#include <optional>
#include "JCameraOrientation.hpp"
#include <functional>
#include "JFunc_void_CameraOrientation.hpp"
#include <NitroModules/JNICallable.hpp>

namespace margelo::nitro::camera {

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

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

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

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

  // Properties
  OrientationSource JHybridOrientationManagerSpec::getSource() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JOrientationSource>()>("getSource");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  std::optional<CameraOrientation> JHybridOrientationManagerSpec::getCurrentOrientation() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JCameraOrientation>()>("getCurrentOrientation");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
  }

  // Methods
  void JHybridOrientationManagerSpec::startOrientationUpdates(const std::function<void(CameraOrientation /* orientation */)>& onChanged) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_CameraOrientation::javaobject> /* onChanged */)>("startOrientationUpdates_cxx");
    method(_javaPart, JFunc_void_CameraOrientation_cxx::fromCpp(onChanged));
  }
  void JHybridOrientationManagerSpec::stopOrientationUpdates() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stopOrientationUpdates");
    method(_javaPart);
  }

} // namespace margelo::nitro::camera
