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

#pragma once

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

#include <optional>
#include <string>

namespace margelo::nitro::fawrypay_rnfawrypaysdk {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MerchantInfo by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MerchantInfo toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldMerchantCode = clazz->getField<jni::JString>("merchantCode");
      jni::local_ref<jni::JString> merchantCode = this->getFieldValue(fieldMerchantCode);
      static const auto fieldMerchantSecretCode = clazz->getField<jni::JString>("merchantSecretCode");
      jni::local_ref<jni::JString> merchantSecretCode = this->getFieldValue(fieldMerchantSecretCode);
      static const auto fieldMerchantRefNum = clazz->getField<jni::JString>("merchantRefNum");
      jni::local_ref<jni::JString> merchantRefNum = this->getFieldValue(fieldMerchantRefNum);
      return MerchantInfo(
        merchantCode->toStdString(),
        merchantSecretCode != nullptr ? std::make_optional(merchantSecretCode->toStdString()) : std::nullopt,
        merchantRefNum->toStdString()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JMerchantInfo::javaobject> fromCpp(const MerchantInfo& value) {
      return newInstance(
        jni::make_jstring(value.merchantCode),
        value.merchantSecretCode.has_value() ? jni::make_jstring(value.merchantSecretCode.value()) : nullptr,
        jni::make_jstring(value.merchantRefNum)
      );
    }
  };

} // namespace margelo::nitro::fawrypay_rnfawrypaysdk
