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

#include "JHybridDepthSpec.hpp"

// Forward declaration of `CameraOrientation` to properly resolve imports.
namespace margelo::nitro::camera { enum class CameraOrientation; }
// Forward declaration of `DepthPixelFormat` to properly resolve imports.
namespace margelo::nitro::camera { enum class DepthPixelFormat; }
// Forward declaration of `DepthDataAccuracy` to properly resolve imports.
namespace margelo::nitro::camera { enum class DepthDataAccuracy; }
// Forward declaration of `DepthDataQuality` to properly resolve imports.
namespace margelo::nitro::camera { enum class DepthDataQuality; }
// Forward declaration of `HybridCameraCalibrationDataSpec` to properly resolve imports.
namespace margelo::nitro::camera { class HybridCameraCalibrationDataSpec; }
// Forward declaration of `NativeBuffer` to properly resolve imports.
namespace margelo::nitro::camera { struct NativeBuffer; }
// Forward declaration of `HybridDepthSpec` to properly resolve imports.
namespace margelo::nitro::camera { class HybridDepthSpec; }
// Forward declaration of `Point` to properly resolve imports.
namespace margelo::nitro::camera { struct Point; }
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
namespace margelo::nitro::camera { class HybridFrameSpec; }

#include "CameraOrientation.hpp"
#include "JCameraOrientation.hpp"
#include "DepthPixelFormat.hpp"
#include "JDepthPixelFormat.hpp"
#include "DepthDataAccuracy.hpp"
#include "JDepthDataAccuracy.hpp"
#include "DepthDataQuality.hpp"
#include "JDepthDataQuality.hpp"
#include <vector>
#include <memory>
#include "HybridCameraCalibrationDataSpec.hpp"
#include <optional>
#include "JHybridCameraCalibrationDataSpec.hpp"
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/JArrayBuffer.hpp>
#include "NativeBuffer.hpp"
#include "JNativeBuffer.hpp"
#include <functional>
#include "JFunc_void.hpp"
#include <NitroModules/JNICallable.hpp>
#include "HybridDepthSpec.hpp"
#include "JHybridDepthSpec.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "Point.hpp"
#include "JPoint.hpp"
#include "HybridFrameSpec.hpp"
#include "JHybridFrameSpec.hpp"

namespace margelo::nitro::camera {

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

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

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

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

  // Properties
  CameraOrientation JHybridDepthSpec::getOrientation() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JCameraOrientation>()>("getOrientation");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  bool JHybridDepthSpec::getIsMirrored() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isMirrored");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  double JHybridDepthSpec::getTimestamp() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getTimestamp");
    auto __result = method(_javaPart);
    return __result;
  }
  double JHybridDepthSpec::getWidth() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getWidth");
    auto __result = method(_javaPart);
    return __result;
  }
  double JHybridDepthSpec::getHeight() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getHeight");
    auto __result = method(_javaPart);
    return __result;
  }
  double JHybridDepthSpec::getBytesPerRow() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getBytesPerRow");
    auto __result = method(_javaPart);
    return __result;
  }
  DepthPixelFormat JHybridDepthSpec::getPixelFormat() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JDepthPixelFormat>()>("getPixelFormat");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  bool JHybridDepthSpec::getIsValid() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isValid");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  bool JHybridDepthSpec::getIsDepthDataFiltered() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isDepthDataFiltered");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  DepthDataAccuracy JHybridDepthSpec::getDepthDataAccuracy() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JDepthDataAccuracy>()>("getDepthDataAccuracy");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  DepthDataQuality JHybridDepthSpec::getDepthDataQuality() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JDepthDataQuality>()>("getDepthDataQuality");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  std::vector<DepthPixelFormat> JHybridDepthSpec::getAvailableDepthPixelFormats() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JDepthPixelFormat>>()>("getAvailableDepthPixelFormats");
    auto __result = method(_javaPart);
    return [&](auto&& __input) {
      size_t __size = __input->size();
      std::vector<DepthPixelFormat> __vector;
      __vector.reserve(__size);
      for (size_t __i = 0; __i < __size; __i++) {
        auto __element = __input->getElement(__i);
        __vector.push_back(__element->toCpp());
      }
      return __vector;
    }(__result);
  }
  std::optional<std::shared_ptr<HybridCameraCalibrationDataSpec>> JHybridDepthSpec::getCameraCalibrationData() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridCameraCalibrationDataSpec::JavaPart>()>("getCameraCalibrationData");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->getJHybridCameraCalibrationDataSpec()) : std::nullopt;
  }

  // Methods
  std::shared_ptr<ArrayBuffer> JHybridDepthSpec::getDepthData() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JArrayBuffer::javaobject>()>("getDepthData");
    auto __result = method(_javaPart);
    return __result->cthis()->getArrayBuffer();
  }
  NativeBuffer JHybridDepthSpec::getNativeBuffer() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JNativeBuffer>()>("getNativeBuffer");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  std::shared_ptr<HybridDepthSpec> JHybridDepthSpec::rotate(CameraOrientation orientation, bool isMirrored) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridDepthSpec::JavaPart>(jni::alias_ref<JCameraOrientation> /* orientation */, jboolean /* isMirrored */)>("rotate");
    auto __result = method(_javaPart, JCameraOrientation::fromCpp(orientation), isMirrored);
    return __result->getJHybridDepthSpec();
  }
  std::shared_ptr<Promise<std::shared_ptr<HybridDepthSpec>>> JHybridDepthSpec::rotateAsync(CameraOrientation orientation, bool isMirrored) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JCameraOrientation> /* orientation */, jboolean /* isMirrored */)>("rotateAsync");
    auto __result = method(_javaPart, JCameraOrientation::fromCpp(orientation), isMirrored);
    return [&]() {
      auto __promise = Promise<std::shared_ptr<HybridDepthSpec>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JHybridDepthSpec::JavaPart>(__boxedResult);
        __promise->resolve(__result->getJHybridDepthSpec());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<HybridDepthSpec> JHybridDepthSpec::convert(DepthPixelFormat pixelFormat) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridDepthSpec::JavaPart>(jni::alias_ref<JDepthPixelFormat> /* pixelFormat */)>("convert");
    auto __result = method(_javaPart, JDepthPixelFormat::fromCpp(pixelFormat));
    return __result->getJHybridDepthSpec();
  }
  std::shared_ptr<Promise<std::shared_ptr<HybridDepthSpec>>> JHybridDepthSpec::convertAsync(DepthPixelFormat pixelFormat) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JDepthPixelFormat> /* pixelFormat */)>("convertAsync");
    auto __result = method(_javaPart, JDepthPixelFormat::fromCpp(pixelFormat));
    return [&]() {
      auto __promise = Promise<std::shared_ptr<HybridDepthSpec>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JHybridDepthSpec::JavaPart>(__boxedResult);
        __promise->resolve(__result->getJHybridDepthSpec());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  Point JHybridDepthSpec::convertCameraPointToDepthPoint(const Point& cameraPoint) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPoint>(jni::alias_ref<JPoint> /* cameraPoint */)>("convertCameraPointToDepthPoint");
    auto __result = method(_javaPart, JPoint::fromCpp(cameraPoint));
    return __result->toCpp();
  }
  Point JHybridDepthSpec::convertDepthPointToCameraPoint(const Point& depthPoint) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPoint>(jni::alias_ref<JPoint> /* depthPoint */)>("convertDepthPointToCameraPoint");
    auto __result = method(_javaPart, JPoint::fromCpp(depthPoint));
    return __result->toCpp();
  }
  std::shared_ptr<HybridFrameSpec> JHybridDepthSpec::toFrame() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridFrameSpec::JavaPart>()>("toFrame");
    auto __result = method(_javaPart);
    return __result->getJHybridFrameSpec();
  }
  std::shared_ptr<Promise<std::shared_ptr<HybridFrameSpec>>> JHybridDepthSpec::toFrameAsync() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("toFrameAsync");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<std::shared_ptr<HybridFrameSpec>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JHybridFrameSpec::JavaPart>(__boxedResult);
        __promise->resolve(__result->getJHybridFrameSpec());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }

} // namespace margelo::nitro::camera
