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

#include "JHybridTextRecognizerSpec.hpp"

// Forward declaration of `RecognizedText` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct RecognizedText; }
// Forward declaration of `TextBlock` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct TextBlock; }
// Forward declaration of `BoundingFrame` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct BoundingFrame; }
// Forward declaration of `CornerPoint` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct CornerPoint; }
// Forward declaration of `TextLine` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct TextLine; }
// Forward declaration of `TextElement` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct TextElement; }
// Forward declaration of `TextRecognitionConfig` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct TextRecognitionConfig; }
// Forward declaration of `ScanRegion` to properly resolve imports.
namespace margelo::nitro::visioncameraocrplus { struct ScanRegion; }

#include "RecognizedText.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "JRecognizedText.hpp"
#include <string>
#include "TextBlock.hpp"
#include <vector>
#include "JTextBlock.hpp"
#include "BoundingFrame.hpp"
#include "JBoundingFrame.hpp"
#include "CornerPoint.hpp"
#include "JCornerPoint.hpp"
#include "TextLine.hpp"
#include "JTextLine.hpp"
#include "TextElement.hpp"
#include "JTextElement.hpp"
#include <optional>
#include "TextRecognitionConfig.hpp"
#include "JTextRecognitionConfig.hpp"
#include "ScanRegion.hpp"
#include "JScanRegion.hpp"

namespace margelo::nitro::visioncameraocrplus {

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

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

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

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

  // Properties
  

  // Methods
  std::shared_ptr<Promise<RecognizedText>> JHybridTextRecognizerSpec::recognizePhoto(const std::string& uri, const std::string& orientation) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<jni::JString> /* orientation */)>("recognizePhoto");
    auto __result = method(_javaPart, jni::make_jstring(uri), jni::make_jstring(orientation));
    return [&]() {
      auto __promise = Promise<RecognizedText>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JRecognizedText>(__boxedResult);
        __promise->resolve(__result->toCpp());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::optional<RecognizedText> JHybridTextRecognizerSpec::scanFrame(uint64_t nativeBufferPointer, const std::string& orientation) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JRecognizedText>(jlong /* nativeBufferPointer */, jni::alias_ref<jni::JString> /* orientation */)>("scanFrame_cxx");
    auto __result = method(_javaPart, nativeBufferPointer, jni::make_jstring(orientation));
    return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
  }
  void JHybridTextRecognizerSpec::configure(const TextRecognitionConfig& config) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JTextRecognitionConfig> /* config */)>("configure");
    method(_javaPart, JTextRecognitionConfig::fromCpp(config));
  }

} // namespace margelo::nitro::visioncameraocrplus
