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

#include "JHybridBarcodeSpec.hpp"

// Forward declaration of `BarcodeFormat` to properly resolve imports.
namespace margelo::nitro::camera::barcodescanner { enum class BarcodeFormat; }
// Forward declaration of `Rect` to properly resolve imports.
namespace margelo::nitro::camera::barcodescanner { struct Rect; }
// Forward declaration of `Point` to properly resolve imports.
namespace margelo::nitro::camera::barcodescanner { struct Point; }
// Forward declaration of `BarcodeValueType` to properly resolve imports.
namespace margelo::nitro::camera::barcodescanner { enum class BarcodeValueType; }

#include "BarcodeFormat.hpp"
#include "JBarcodeFormat.hpp"
#include "Rect.hpp"
#include "JRect.hpp"
#include "Point.hpp"
#include <vector>
#include "JPoint.hpp"
#include <string>
#include <optional>
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/JArrayBuffer.hpp>
#include "BarcodeValueType.hpp"
#include "JBarcodeValueType.hpp"

namespace margelo::nitro::camera::barcodescanner {

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

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

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

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

  // Properties
  BarcodeFormat JHybridBarcodeSpec::getFormat() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JBarcodeFormat>()>("getFormat");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  Rect JHybridBarcodeSpec::getBoundingBox() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JRect>()>("getBoundingBox");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }
  std::vector<Point> JHybridBarcodeSpec::getCornerPoints() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JPoint>>()>("getCornerPoints");
    auto __result = method(_javaPart);
    return [&](auto&& __input) {
      size_t __size = __input->size();
      std::vector<Point> __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::string> JHybridBarcodeSpec::getDisplayValue() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getDisplayValue");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
  }
  std::optional<std::shared_ptr<ArrayBuffer>> JHybridBarcodeSpec::getRawBytes() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JArrayBuffer::javaobject>()>("getRawBytes");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->cthis()->getArrayBuffer()) : std::nullopt;
  }
  std::optional<std::string> JHybridBarcodeSpec::getRawValue() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getRawValue");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
  }
  BarcodeValueType JHybridBarcodeSpec::getValueType() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JBarcodeValueType>()>("getValueType");
    auto __result = method(_javaPart);
    return __result->toCpp();
  }

  // Methods
  

} // namespace margelo::nitro::camera::barcodescanner
