///
/// JMailAuthConfig.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 "MailAuthConfig.hpp"

#include "JMailAuthType.hpp"
#include "MailAuthType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::mailengine {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MailAuthConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MailAuthConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JMailAuthType>("type");
      jni::local_ref<JMailAuthType> type = this->getFieldValue(fieldType);
      static const auto fieldUser = clazz->getField<jni::JString>("user");
      jni::local_ref<jni::JString> user = this->getFieldValue(fieldUser);
      static const auto fieldPassword = clazz->getField<jni::JString>("password");
      jni::local_ref<jni::JString> password = this->getFieldValue(fieldPassword);
      static const auto fieldAccessToken = clazz->getField<jni::JString>("accessToken");
      jni::local_ref<jni::JString> accessToken = this->getFieldValue(fieldAccessToken);
      return MailAuthConfig(
        type->toCpp(),
        user->toStdString(),
        password != nullptr ? std::make_optional(password->toStdString()) : std::nullopt,
        accessToken != nullptr ? std::make_optional(accessToken->toStdString()) : 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<JMailAuthConfig::javaobject> fromCpp(const MailAuthConfig& value) {
      using JSignature = JMailAuthConfig(jni::alias_ref<JMailAuthType>, jni::alias_ref<jni::JString>, 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,
        JMailAuthType::fromCpp(value.type),
        jni::make_jstring(value.user),
        value.password.has_value() ? jni::make_jstring(value.password.value()) : nullptr,
        value.accessToken.has_value() ? jni::make_jstring(value.accessToken.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::mailengine
