///
/// JSettingData.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 "SettingData.hpp"

#include "JThemeSettings.hpp"
#include "ThemeSettings.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::taponpagseguro {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct SettingData by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    SettingData toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldApp_key = clazz->getField<jni::JString>("app_key");
      jni::local_ref<jni::JString> app_key = this->getFieldValue(fieldApp_key);
      static const auto fieldApp_name = clazz->getField<jni::JString>("app_name");
      jni::local_ref<jni::JString> app_name = this->getFieldValue(fieldApp_name);
      static const auto fieldApp_version = clazz->getField<jni::JString>("app_version");
      jni::local_ref<jni::JString> app_version = this->getFieldValue(fieldApp_version);
      static const auto fieldEnable_taxpass_through = clazz->getField<jni::JBoolean>("enable_taxpass_through");
      jni::local_ref<jni::JBoolean> enable_taxpass_through = this->getFieldValue(fieldEnable_taxpass_through);
      static const auto fieldTheme = clazz->getField<JThemeSettings>("theme");
      jni::local_ref<JThemeSettings> theme = this->getFieldValue(fieldTheme);
      return SettingData(
        app_key->toStdString(),
        app_name->toStdString(),
        app_version->toStdString(),
        enable_taxpass_through != nullptr ? std::make_optional(static_cast<bool>(enable_taxpass_through->value())) : std::nullopt,
        theme != nullptr ? std::make_optional(theme->toCpp()) : std::nullopt
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JSettingData::javaobject> fromCpp(const SettingData& value) {
      using JSignature = JSettingData(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JThemeSettings>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.app_key),
        jni::make_jstring(value.app_name),
        jni::make_jstring(value.app_version),
        value.enable_taxpass_through.has_value() ? jni::JBoolean::valueOf(value.enable_taxpass_through.value()) : nullptr,
        value.theme.has_value() ? JThemeSettings::fromCpp(value.theme.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::taponpagseguro
