///
/// JFunc_void_FetchNativeResponse.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 <functional>

#include "FetchNativeResponse.hpp"
#include <functional>
#include <NitroModules/JNICallable.hpp>
#include "JFetchNativeResponse.hpp"
#include <string>
#include "FetchHeader.hpp"
#include <vector>
#include "JFetchHeader.hpp"

namespace margelo::nitro::one {

  using namespace facebook;

  /**
   * Represents the Java/Kotlin callback `(response: FetchNativeResponse) -> Unit`.
   * This can be passed around between C++ and Java/Kotlin.
   */
  struct JFunc_void_FetchNativeResponse: public jni::JavaClass<JFunc_void_FetchNativeResponse> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/one/Func_void_FetchNativeResponse;";

  public:
    /**
     * Invokes the function this `JFunc_void_FetchNativeResponse` instance holds through JNI.
     */
    void invoke(const FetchNativeResponse& response) const {
      static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFetchNativeResponse> /* response */)>("invoke");
      method(self(), JFetchNativeResponse::fromCpp(response));
    }
  };

  /**
   * An implementation of Func_void_FetchNativeResponse that is backed by a C++ implementation (using `std::function<...>`)
   */
  class JFunc_void_FetchNativeResponse_cxx final: public jni::HybridClass<JFunc_void_FetchNativeResponse_cxx, JFunc_void_FetchNativeResponse> {
  public:
    static jni::local_ref<JFunc_void_FetchNativeResponse::javaobject> fromCpp(const std::function<void(const FetchNativeResponse& /* response */)>& func) {
      return JFunc_void_FetchNativeResponse_cxx::newObjectCxxArgs(func);
    }

  public:
    /**
     * Invokes the C++ `std::function<...>` this `JFunc_void_FetchNativeResponse_cxx` instance holds.
     */
    void invoke_cxx(jni::alias_ref<JFetchNativeResponse> response) {
      _func(response->toCpp());
    }

  public:
    [[nodiscard]]
    inline const std::function<void(const FetchNativeResponse& /* response */)>& getFunction() const {
      return _func;
    }

  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/one/Func_void_FetchNativeResponse_cxx;";
    static void registerNatives() {
      registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_FetchNativeResponse_cxx::invoke_cxx)});
    }

  private:
    explicit JFunc_void_FetchNativeResponse_cxx(const std::function<void(const FetchNativeResponse& /* response */)>& func): _func(func) { }

  private:
    friend HybridBase;
    std::function<void(const FetchNativeResponse& /* response */)> _func;
  };

} // namespace margelo::nitro::one
