///
/// JMailAccountConfig.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 "MailAccountConfig.hpp"

#include "JMailAuthConfig.hpp"
#include "JMailAuthType.hpp"
#include "JMailSecurity.hpp"
#include "JMailServerConfig.hpp"
#include "MailAuthConfig.hpp"
#include "MailAuthType.hpp"
#include "MailSecurity.hpp"
#include "MailServerConfig.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::mailengine {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MailAccountConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MailAccountConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldImap = clazz->getField<JMailServerConfig>("imap");
      jni::local_ref<JMailServerConfig> imap = this->getFieldValue(fieldImap);
      static const auto fieldSmtp = clazz->getField<JMailServerConfig>("smtp");
      jni::local_ref<JMailServerConfig> smtp = this->getFieldValue(fieldSmtp);
      static const auto fieldAuth = clazz->getField<JMailAuthConfig>("auth");
      jni::local_ref<JMailAuthConfig> auth = this->getFieldValue(fieldAuth);
      static const auto fieldConnectionTimeoutMs = clazz->getField<jni::JDouble>("connectionTimeoutMs");
      jni::local_ref<jni::JDouble> connectionTimeoutMs = this->getFieldValue(fieldConnectionTimeoutMs);
      static const auto fieldId = clazz->getField<jni::JString>("id");
      jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
      return MailAccountConfig(
        imap->toCpp(),
        smtp != nullptr ? std::make_optional(smtp->toCpp()) : std::nullopt,
        auth->toCpp(),
        connectionTimeoutMs != nullptr ? std::make_optional(connectionTimeoutMs->value()) : std::nullopt,
        id != nullptr ? std::make_optional(id->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<JMailAccountConfig::javaobject> fromCpp(const MailAccountConfig& value) {
      using JSignature = JMailAccountConfig(jni::alias_ref<JMailServerConfig>, jni::alias_ref<JMailServerConfig>, jni::alias_ref<JMailAuthConfig>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JMailServerConfig::fromCpp(value.imap),
        value.smtp.has_value() ? JMailServerConfig::fromCpp(value.smtp.value()) : nullptr,
        JMailAuthConfig::fromCpp(value.auth),
        value.connectionTimeoutMs.has_value() ? jni::JDouble::valueOf(value.connectionTimeoutMs.value()) : nullptr,
        value.id.has_value() ? jni::make_jstring(value.id.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::mailengine
