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

#ifndef BUILDING_NITROMMKV_WITH_GENERATED_CMAKE_PROJECT
#error NitroMmkvOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
#endif

#include "NitroMmkvOnLoad.hpp"

#include <jni.h>
#include <fbjni/fbjni.h>
#include <NitroModules/HybridObjectRegistry.hpp>

#include "JHybridMMKVPlatformContextSpec.hpp"
#include "HybridMMKVFactory.hpp"
#include <NitroModules/DefaultConstructableObject.hpp>

namespace margelo::nitro::mmkv {

int initialize(JavaVM* vm) {
  return facebook::jni::initialize(vm, []() {
    ::margelo::nitro::mmkv::registerAllNatives();
  });
}

struct JHybridMMKVPlatformContextSpecImpl: public jni::JavaClass<JHybridMMKVPlatformContextSpecImpl, JHybridMMKVPlatformContextSpec::JavaPart> {
  static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/mmkv/HybridMMKVPlatformContext;";
  static std::shared_ptr<JHybridMMKVPlatformContextSpec> create() {
    static auto constructorFn = javaClassStatic()->getConstructor<JHybridMMKVPlatformContextSpecImpl::javaobject()>();
    jni::local_ref<JHybridMMKVPlatformContextSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
    return javaPart->getJHybridMMKVPlatformContextSpec();
  }
};

void registerAllNatives() {
  using namespace margelo::nitro;
  using namespace margelo::nitro::mmkv;

  // Register native JNI methods
  margelo::nitro::mmkv::JHybridMMKVPlatformContextSpec::CxxPart::registerNatives();

  // Register Nitro Hybrid Objects
  HybridObjectRegistry::registerHybridObjectConstructor(
    "MMKVFactory",
    []() -> std::shared_ptr<HybridObject> {
      static_assert(std::is_default_constructible_v<HybridMMKVFactory>,
                    "The HybridObject \"HybridMMKVFactory\" is not default-constructible! "
                    "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
      return std::make_shared<HybridMMKVFactory>();
    }
  );
  HybridObjectRegistry::registerHybridObjectConstructor(
    "MMKVPlatformContext",
    []() -> std::shared_ptr<HybridObject> {
      return JHybridMMKVPlatformContextSpecImpl::create();
    }
  );
}

} // namespace margelo::nitro::mmkv
