///
/// JScannedBarcode.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 "ScannedBarcode.hpp"

#include "BarcodeFormat.hpp"
#include "JBarcodeFormat.hpp"
#include <string>

namespace margelo::nitro::datascanner {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ScannedBarcode by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ScannedBarcode toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldValue = clazz->getField<jni::JString>("value");
      jni::local_ref<jni::JString> value = this->getFieldValue(fieldValue);
      static const auto fieldFormat = clazz->getField<JBarcodeFormat>("format");
      jni::local_ref<JBarcodeFormat> format = this->getFieldValue(fieldFormat);
      return ScannedBarcode(
        value->toStdString(),
        format->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JScannedBarcode::javaobject> fromCpp(const ScannedBarcode& value) {
      using JSignature = JScannedBarcode(jni::alias_ref<jni::JString>, jni::alias_ref<JBarcodeFormat>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.value),
        JBarcodeFormat::fromCpp(value.format)
      );
    }
  };

} // namespace margelo::nitro::datascanner
