// This file was generated by
//     //third_party/jni_zero/jni_zero.py
// For
//     org.jni_zero.SampleUniqueAnnotations

#ifndef org_jni_1zero_SampleUniqueAnnotations_JNI
#define org_jni_1zero_SampleUniqueAnnotations_JNI

#include <jni.h>

#include "overridden/jni_zero_internal.h"
#include "extra_include.h"
#include "SampleUniqueAnnotations_shared_jni.h"

// Field, class, and method accessors use inline functions with static
// variables for caching.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunique-object-duplication"

// Example signatures (to be implemented by #including file).
// * JNIEnv* parameters are optional.
// * Types do not have to be exact; they must accept rvalues of the examples.
//
// static int32_t JNI_SampleUniqueAnnotations_Bar(JNIEnv* env, int32_t x, int32_t y);
//
// static void JNI_SampleUniqueAnnotations_Baz(
//     JNIEnv* env,
//     const jni_zero::JavaRef<::org::jni_zero::JSampleUniqueAnnotations_Handle>& handle);
//
// void FooAndroid::BarDelegate::Foo(JNIEnv* env, const std::string& arg);
//

// Triggers a compiler warning if DEFINE_JNI(SampleUniqueAnnotations) is forgotten (requires -Wunused-function).
static void YouForgotToCallMacro_DEFINE_JNI_SampleUniqueAnnotations() {}

// Java to native functions
#define DEFINE_JNI_FOR_SampleUniqueAnnotations()                                                   \
  namespace {                                                                                      \
                                                                                                   \
  JNI_ZERO_BOUNDARY_EXPORT int32_t Java_org_jni_1zero_GEN_1JNI_org_1jni_11zero_1SampleUniqueAnnotations_1bar( \
      JNIEnv* env,                                                                                 \
      jclass jcaller,                                                                              \
      int32_t x,                                                                                   \
      int32_t y) {                                                                                 \
    /* Prevent -Wunused-function warning. */                                                       \
    YouForgotToCallMacro_DEFINE_JNI_SampleUniqueAnnotations();                                     \
                                                                                                   \
    /* Lambda required to make "if constexpr" work properly. */                                    \
    auto dependent_context = [&](auto) {                                                           \
      /* Lambda required to disambiguate overloads. */                                             \
      auto func_wrapper = [&](auto&&... args) ->                                                   \
      decltype(JNI_SampleUniqueAnnotations_Bar(std::forward<decltype(args)>(args)...)) {           \
        return JNI_SampleUniqueAnnotations_Bar(std::forward<decltype(args)>(args)...);             \
      };                                                                                           \
      if constexpr (requires { func_wrapper(env, x, y); }) {                                       \
        return func_wrapper(env, x, y);                                                            \
      } else if constexpr (requires { func_wrapper(x, y); }) {                                     \
        return func_wrapper(x, y);                                                                 \
      } else {                                                                                     \
        static_assert(false, "JNI_SampleUniqueAnnotations_Bar() is missing or has incorrect signature.\nIt should accept an optional JNIEnv* parameter as well as rvalues of the given types: (int32_t, int32_t)\nSee SampleUniqueAnnotations_jni.h for an example."); \
      }                                                                                            \
    };                                                                                             \
    auto return_value = dependent_context(0);                                                      \
    return return_value;                                                                           \
  }                                                                                                \
                                                                                                   \
  JNI_ZERO_BOUNDARY_EXPORT void Java_org_jni_1zero_GEN_1JNI_org_1jni_11zero_1SampleUniqueAnnotations_1baz( \
      JNIEnv* env,                                                                                 \
      jclass jcaller,                                                                              \
      jobject handle) {                                                                            \
    auto handle_ref = jni_zero::JavaRef<::org::jni_zero::JSampleUniqueAnnotations_Handle>::CreateLeaky(env, \
        static_cast<::org::jni_zero::JSampleUniqueAnnotations_Handle>(handle));                    \
    /* Lambda required to make "if constexpr" work properly. */                                    \
    auto dependent_context = [&](auto) {                                                           \
      /* Lambda required to disambiguate overloads. */                                             \
      auto func_wrapper = [&](auto&&... args) ->                                                   \
      decltype(JNI_SampleUniqueAnnotations_Baz(std::forward<decltype(args)>(args)...)) {           \
        return JNI_SampleUniqueAnnotations_Baz(std::forward<decltype(args)>(args)...);             \
      };                                                                                           \
      if constexpr (requires { func_wrapper(env, handle_ref); }) {                                 \
        return func_wrapper(env, handle_ref);                                                      \
      } else if constexpr (requires { func_wrapper(handle_ref); }) {                               \
        return func_wrapper(handle_ref);                                                           \
      } else {                                                                                     \
        static_assert(false, "JNI_SampleUniqueAnnotations_Baz() is missing or has incorrect signature.\nIt should accept an optional JNIEnv* parameter as well as rvalues of the given types: (const jni_zero::JavaRef<JSampleUniqueAnnotations_Handle>&)\nSee SampleUniqueAnnotations_jni.h for an example."); \
      }                                                                                            \
    };                                                                                             \
    dependent_context(0);                                                                          \
  }                                                                                                \
                                                                                                   \
  JNI_ZERO_BOUNDARY_EXPORT void Java_org_jni_1zero_GEN_1JNI_org_1jni_11zero_1SampleUniqueAnnotations_1foo( \
      JNIEnv* env,                                                                                 \
      jclass jcaller,                                                                              \
      int64_t nativePtr,                                                                           \
      jobject arg) {                                                                               \
    std::string arg_converted = jni_zero::FromJniType<std::string>(                                \
        env,                                                                                       \
        jni_zero::JavaRef<jobject>::CreateLeaky(env, arg));                                        \
    FooAndroid::BarDelegate* _ptr = reinterpret_cast<FooAndroid::BarDelegate*>(nativePtr);         \
    /* Lambda required to make "if constexpr" work properly. */                                    \
    auto dependent_context = [&](auto) {                                                           \
      /* Lambda required to disambiguate overloads. */                                             \
      auto func_wrapper = [&](auto&&... args) ->                                                   \
      decltype(_ptr->Foo(std::forward<decltype(args)>(args)...)) {                                 \
        return _ptr->Foo(std::forward<decltype(args)>(args)...);                                   \
      };                                                                                           \
      if constexpr (requires { func_wrapper(env, std::move(arg_converted)); }) {                   \
        return func_wrapper(env, std::move(arg_converted));                                        \
      } else if constexpr (requires { func_wrapper(std::move(arg_converted)); }) {                 \
        return func_wrapper(std::move(arg_converted));                                             \
      } else {                                                                                     \
        static_assert(false, "FooAndroid::BarDelegate::Foo() is missing or has incorrect signature.\nIt should accept an optional JNIEnv* parameter as well as rvalues of the given types: (std::string)\nSee SampleUniqueAnnotations_jni.h for an example."); \
      }                                                                                            \
    };                                                                                             \
    dependent_context(0);                                                                          \
  }                                                                                                \
                                                                                                   \
                                                                                                   \
  }  /* namespace */

// Class Accessors
#ifndef org_jni_1zero_SampleUniqueAnnotations_clazz_defined
#define org_jni_1zero_SampleUniqueAnnotations_clazz_defined
inline jclass org_jni_1zero_SampleUniqueAnnotations_clazz(JNIEnv* env) {
  static const char kClassName[] = "org.jni_zero.SampleUniqueAnnotations";
  static std::atomic<jclass> cached_class;
  return jni_zero::internal::LazyGetClass(env, kClassName, &cached_class);
}
#endif


// Native to Java functions
static void Java_SampleUniqueAnnotations_useBar1(
    JNIEnv* env,
    const ::jni_zero::JavaRef<jobject>& inner) {
  static std::atomic<jmethodID> cached_method_id(nullptr);
  jclass clazz = org_jni_1zero_SampleUniqueAnnotations_clazz(env);
  CHECK_CLAZZ(env, clazz, clazz);
  ::jni_zero::internal::JniJavaCallContext<true> call_context;
  call_context.Init<::jni_zero::MethodID::TYPE_STATIC>(
      env,
      clazz,
      "useBar1",
      "(Lorg/jni_zero/Bar1$Inner;)V",
      &cached_method_id);
  env->CallStaticVoidMethod(clazz, call_context.method_id(), inner.obj());
}


// jobject-subclass-aware definitions:
namespace jni_zero_internal {

template<>
class _CalledByNativesStatics<::org::jni_zero::JSampleUniqueAnnotations> {
  public:
  static void useBar1(JNIEnv* env, const ::jni_zero::JavaRef<::org::jni_zero::JBar1_Inner>& inner) {
    Java_SampleUniqueAnnotations_useBar1(env, inner);
  }

};


}  // namespace jni_zero_internal

namespace org::jni_zero {
using SampleUniqueAnnotationsJni = ::jni_zero_internal::_CalledByNativesStatics<::org::jni_zero::JSampleUniqueAnnotations>;
}
#ifndef _JNI_ZERO_SampleUniqueAnnotationsJni_DEFINED
#define _JNI_ZERO_SampleUniqueAnnotationsJni_DEFINED
using ::org::jni_zero::SampleUniqueAnnotationsJni;
#endif


#pragma clang diagnostic pop
#endif  // org_jni_1zero_SampleUniqueAnnotations_JNI
