///
/// JNitroFormDataPart.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 "NitroFormDataPart.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::nitrofetch {

  using namespace facebook;

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

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

} // namespace margelo::nitro::nitrofetch
