///
/// JMailAttachmentStruct.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 "MailAttachmentStruct.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 "MailAttachmentStruct" and the the Kotlin data class "MailAttachmentStruct".
   */
  struct JMailAttachmentStruct final: public jni::JavaClass<JMailAttachmentStruct> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/mailengine/MailAttachmentStruct;";

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

} // namespace margelo::nitro::mailengine
