///
/// JSensitiveInfoItem.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 "SensitiveInfoItem.hpp"

#include "AccessControl.hpp"
#include "JAccessControl.hpp"
#include "JSecurityLevel.hpp"
#include "JStorageBackend.hpp"
#include "JStorageMetadata.hpp"
#include "SecurityLevel.hpp"
#include "StorageBackend.hpp"
#include "StorageMetadata.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::sensitiveinfo {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct SensitiveInfoItem by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    SensitiveInfoItem toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldKey = clazz->getField<jni::JString>("key");
      jni::local_ref<jni::JString> key = this->getFieldValue(fieldKey);
      static const auto fieldService = clazz->getField<jni::JString>("service");
      jni::local_ref<jni::JString> service = this->getFieldValue(fieldService);
      static const auto fieldValue = clazz->getField<jni::JString>("value");
      jni::local_ref<jni::JString> value = this->getFieldValue(fieldValue);
      static const auto fieldMetadata = clazz->getField<JStorageMetadata>("metadata");
      jni::local_ref<JStorageMetadata> metadata = this->getFieldValue(fieldMetadata);
      return SensitiveInfoItem(
        key->toStdString(),
        service->toStdString(),
        value != nullptr ? std::make_optional(value->toStdString()) : std::nullopt,
        metadata->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<JSensitiveInfoItem::javaobject> fromCpp(const SensitiveInfoItem& value) {
      using JSignature = JSensitiveInfoItem(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JStorageMetadata>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.key),
        jni::make_jstring(value.service),
        value.value.has_value() ? jni::make_jstring(value.value.value()) : nullptr,
        JStorageMetadata::fromCpp(value.metadata)
      );
    }
  };

} // namespace margelo::nitro::sensitiveinfo
