///
/// JFetchNativeResponse.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 "FetchNativeResponse.hpp"

#include "FetchHeader.hpp"
#include "JFetchHeader.hpp"
#include <string>
#include <vector>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct FetchNativeResponse by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    FetchNativeResponse toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldStatus = clazz->getField<double>("status");
      double status = this->getFieldValue(fieldStatus);
      static const auto fieldStatusText = clazz->getField<jni::JString>("statusText");
      jni::local_ref<jni::JString> statusText = this->getFieldValue(fieldStatusText);
      static const auto fieldUrl = clazz->getField<jni::JString>("url");
      jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
      static const auto fieldRedirected = clazz->getField<jboolean>("redirected");
      jboolean redirected = this->getFieldValue(fieldRedirected);
      static const auto fieldHeaders = clazz->getField<jni::JArrayClass<JFetchHeader>>("headers");
      jni::local_ref<jni::JArrayClass<JFetchHeader>> headers = this->getFieldValue(fieldHeaders);
      return FetchNativeResponse(
        status,
        statusText->toStdString(),
        url->toStdString(),
        static_cast<bool>(redirected),
        [&](auto&& __input) {
          size_t __size = __input->size();
          std::vector<FetchHeader> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __input->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }(headers)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JFetchNativeResponse::javaobject> fromCpp(const FetchNativeResponse& value) {
      using JSignature = JFetchNativeResponse(double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jboolean, jni::alias_ref<jni::JArrayClass<JFetchHeader>>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.status,
        jni::make_jstring(value.statusText),
        jni::make_jstring(value.url),
        value.redirected,
        [&](auto&& __input) {
          size_t __size = __input.size();
          jni::local_ref<jni::JArrayClass<JFetchHeader>> __array = jni::JArrayClass<JFetchHeader>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = __input[__i];
            auto __elementJni = JFetchHeader::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(value.headers)
      );
    }
  };

} // namespace margelo::nitro::one
