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

#pragma once

#include <fbjni/fbjni.h>
#include <functional>

#include "TextTrack.hpp"
#include <optional>
#include <functional>
#include "JTextTrack.hpp"
#include <string>

namespace margelo::nitro::video {

  using namespace facebook;

  /**
   * Represents the Java/Kotlin callback `(track: TextTrack?) -> Unit`.
   * This can be passed around between C++ and Java/Kotlin.
   */
  struct JFunc_void_std__optional_TextTrack_: public jni::JavaClass<JFunc_void_std__optional_TextTrack_> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/video/Func_void_std__optional_TextTrack_;";

  public:
    /**
     * Invokes the function this `JFunc_void_std__optional_TextTrack_` instance holds through JNI.
     */
    void invoke(const std::optional<TextTrack>& track) const {
      static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JTextTrack> /* track */)>("invoke");
      method(self(), track.has_value() ? JTextTrack::fromCpp(track.value()) : nullptr);
    }
  };

  /**
   * An implementation of Func_void_std__optional_TextTrack_ that is backed by a C++ implementation (using `std::function<...>`)
   */
  struct JFunc_void_std__optional_TextTrack__cxx final: public jni::HybridClass<JFunc_void_std__optional_TextTrack__cxx, JFunc_void_std__optional_TextTrack_> {
  public:
    static jni::local_ref<JFunc_void_std__optional_TextTrack_::javaobject> fromCpp(const std::function<void(const std::optional<TextTrack>& /* track */)>& func) {
      return JFunc_void_std__optional_TextTrack__cxx::newObjectCxxArgs(func);
    }

  public:
    /**
     * Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_TextTrack__cxx` instance holds.
     */
    void invoke_cxx(jni::alias_ref<JTextTrack> track) {
      _func(track != nullptr ? std::make_optional(track->toCpp()) : std::nullopt);
    }

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

  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/video/Func_void_std__optional_TextTrack__cxx;";
    static void registerNatives() {
      registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__optional_TextTrack__cxx::invoke_cxx)});
    }

  private:
    explicit JFunc_void_std__optional_TextTrack__cxx(const std::function<void(const std::optional<TextTrack>& /* track */)>& func): _func(func) { }

  private:
    friend HybridBase;
    std::function<void(const std::optional<TextTrack>& /* track */)> _func;
  };

} // namespace margelo::nitro::video
