///
/// JRequestOptions.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "RequestOptions.hpp"

#include "HybridInputStreamSpec.hpp"
#include "JHybridInputStreamSpec.hpp"
#include "JRequestMethod.hpp"
#include "RequestMethod.hpp"
#include <NitroModules/JNISharedPtr.hpp>
#include <memory>
#include <optional>
#include <string>

namespace margelo::nitro::fastio {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct RequestOptions by copying all values to C++.
     */
    [[maybe_unused]]
    RequestOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldUrl = clazz->getField<jni::JString>("url");
      jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
      static const auto fieldMethod = clazz->getField<JRequestMethod>("method");
      jni::local_ref<JRequestMethod> method = this->getFieldValue(fieldMethod);
      static const auto fieldBody = clazz->getField<JHybridInputStreamSpec::javaobject>("body");
      jni::local_ref<JHybridInputStreamSpec::javaobject> body = this->getFieldValue(fieldBody);
      return RequestOptions(
        url->toStdString(),
        method->toCpp(),
        body != nullptr ? std::make_optional(JNISharedPtr::make_shared_from_jni<JHybridInputStreamSpec>(jni::make_global(body))) : 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<JRequestOptions::javaobject> fromCpp(const RequestOptions& value) {
      return newInstance(
        jni::make_jstring(value.url),
        JRequestMethod::fromCpp(value.method),
        value.body.has_value() ? std::dynamic_pointer_cast<JHybridInputStreamSpec>(value.body.value())->getJavaPart() : nullptr
      );
    }
  };

} // namespace margelo::nitro::fastio
