///
/// JMailAddressStruct.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 "MailAddressStruct.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::mailengine {

  using namespace facebook;

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

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

} // namespace margelo::nitro::mailengine
