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

#pragma once

#include <fbjni/fbjni.h>
#include "TextRecognitionConfig.hpp"

#include "JScanRegion.hpp"
#include "ScanRegion.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::visioncameraocrplus {

  using namespace facebook;

  /**
   * The C++ JNI bridge between the C++ struct "TextRecognitionConfig" and the the Kotlin data class "TextRecognitionConfig".
   */
  struct JTextRecognitionConfig final: public jni::JavaClass<JTextRecognitionConfig> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visioncameraocrplus/TextRecognitionConfig;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct TextRecognitionConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    TextRecognitionConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldLanguage = clazz->getField<jni::JString>("language");
      jni::local_ref<jni::JString> language = this->getFieldValue(fieldLanguage);
      static const auto fieldScanRegion = clazz->getField<JScanRegion>("scanRegion");
      jni::local_ref<JScanRegion> scanRegion = this->getFieldValue(fieldScanRegion);
      static const auto fieldFrameSkipThreshold = clazz->getField<double>("frameSkipThreshold");
      double frameSkipThreshold = this->getFieldValue(fieldFrameSkipThreshold);
      static const auto fieldUseLightweightMode = clazz->getField<jboolean>("useLightweightMode");
      jboolean useLightweightMode = this->getFieldValue(fieldUseLightweightMode);
      return TextRecognitionConfig(
        language->toStdString(),
        scanRegion != nullptr ? std::make_optional(scanRegion->toCpp()) : std::nullopt,
        frameSkipThreshold,
        static_cast<bool>(useLightweightMode)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JTextRecognitionConfig::javaobject> fromCpp(const TextRecognitionConfig& value) {
      using JSignature = JTextRecognitionConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JScanRegion>, double, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.language),
        value.scanRegion.has_value() ? JScanRegion::fromCpp(value.scanRegion.value()) : nullptr,
        value.frameSkipThreshold,
        value.useLightweightMode
      );
    }
  };

} // namespace margelo::nitro::visioncameraocrplus
