///
/// JMailOutgoingAttachment.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 "MailOutgoingAttachment.hpp"

#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/JArrayBuffer.hpp>
#include <optional>
#include <string>

namespace margelo::nitro::mailengine {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MailOutgoingAttachment by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MailOutgoingAttachment toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldFilename = clazz->getField<jni::JString>("filename");
      jni::local_ref<jni::JString> filename = this->getFieldValue(fieldFilename);
      static const auto fieldMimeType = clazz->getField<jni::JString>("mimeType");
      jni::local_ref<jni::JString> mimeType = this->getFieldValue(fieldMimeType);
      static const auto fieldPath = clazz->getField<jni::JString>("path");
      jni::local_ref<jni::JString> path = this->getFieldValue(fieldPath);
      static const auto fieldData = clazz->getField<JArrayBuffer::javaobject>("data");
      jni::local_ref<JArrayBuffer::javaobject> data = this->getFieldValue(fieldData);
      static const auto fieldContentId = clazz->getField<jni::JString>("contentId");
      jni::local_ref<jni::JString> contentId = this->getFieldValue(fieldContentId);
      static const auto fieldInline = clazz->getField<jni::JBoolean>("inline");
      jni::local_ref<jni::JBoolean> inline = this->getFieldValue(fieldInline);
      return MailOutgoingAttachment(
        filename->toStdString(),
        mimeType != nullptr ? std::make_optional(mimeType->toStdString()) : std::nullopt,
        path != nullptr ? std::make_optional(path->toStdString()) : std::nullopt,
        data != nullptr ? std::make_optional(data->cthis()->getArrayBuffer()) : std::nullopt,
        contentId != nullptr ? std::make_optional(contentId->toStdString()) : std::nullopt,
        inline != nullptr ? std::make_optional(static_cast<bool>(inline->value())) : 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<JMailOutgoingAttachment::javaobject> fromCpp(const MailOutgoingAttachment& value) {
      using JSignature = JMailOutgoingAttachment(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JArrayBuffer::javaobject>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.filename),
        value.mimeType.has_value() ? jni::make_jstring(value.mimeType.value()) : nullptr,
        value.path.has_value() ? jni::make_jstring(value.path.value()) : nullptr,
        value.data.has_value() ? JArrayBuffer::wrap(value.data.value()) : nullptr,
        value.contentId.has_value() ? jni::make_jstring(value.contentId.value()) : nullptr,
        value.inline.has_value() ? jni::JBoolean::valueOf(value.inline.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::mailengine
