///
/// JFetchFormPart.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 "FetchFormPart.hpp"

#include "FetchBlobRef.hpp"
#include "JFetchBlobRef.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct FetchFormPart by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    FetchFormPart 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 fieldUri = clazz->getField<jni::JString>("uri");
      jni::local_ref<jni::JString> uri = this->getFieldValue(fieldUri);
      static const auto fieldBlob = clazz->getField<JFetchBlobRef>("blob");
      jni::local_ref<JFetchBlobRef> blob = this->getFieldValue(fieldBlob);
      static const auto fieldFilename = clazz->getField<jni::JString>("filename");
      jni::local_ref<jni::JString> filename = this->getFieldValue(fieldFilename);
      static const auto fieldType = clazz->getField<jni::JString>("type");
      jni::local_ref<jni::JString> type = this->getFieldValue(fieldType);
      return FetchFormPart(
        name->toStdString(),
        value != nullptr ? std::make_optional(value->toStdString()) : std::nullopt,
        uri != nullptr ? std::make_optional(uri->toStdString()) : std::nullopt,
        blob != nullptr ? std::make_optional(blob->toCpp()) : std::nullopt,
        filename != nullptr ? std::make_optional(filename->toStdString()) : std::nullopt,
        type != nullptr ? std::make_optional(type->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<JFetchFormPart::javaobject> fromCpp(const FetchFormPart& value) {
      using JSignature = JFetchFormPart(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JFetchBlobRef>, 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.uri.has_value() ? jni::make_jstring(value.uri.value()) : nullptr,
        value.blob.has_value() ? JFetchBlobRef::fromCpp(value.blob.value()) : nullptr,
        value.filename.has_value() ? jni::make_jstring(value.filename.value()) : nullptr,
        value.type.has_value() ? jni::make_jstring(value.type.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
