///
/// JFunc_void_Progress.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 "Progress.hpp"
#include <functional>
#include <NitroModules/JNICallable.hpp>
#include "JProgress.hpp"
#include <optional>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

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

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

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

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

  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/videopipeline/Func_void_Progress_cxx;";
    static void registerNatives() {
      registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_Progress_cxx::invoke_cxx)});
    }

  private:
    explicit JFunc_void_Progress_cxx(const std::function<void(const Progress& /* p */)>& func): _func(func) { }

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

} // namespace margelo::nitro::videopipeline
