///
/// JFunc_void_MailErrorStruct.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 "MailErrorStruct.hpp"
#include <functional>
#include <NitroModules/JNICallable.hpp>
#include "JMailErrorStruct.hpp"
#include <string>

namespace margelo::nitro::mailengine {

  using namespace facebook;

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

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

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

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

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

  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/mailengine/Func_void_MailErrorStruct_cxx;";
    static void registerNatives() {
      registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_MailErrorStruct_cxx::invoke_cxx)});
    }

  private:
    explicit JFunc_void_MailErrorStruct_cxx(const std::function<void(const MailErrorStruct& /* error */)>& func): _func(func) { }

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

} // namespace margelo::nitro::mailengine
