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

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

#include "NitroReadiumOnLoad.hpp"

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

#include "JHybridReadiumViewSpec.hpp"
#include "JFunc_void_Locator.hpp"
#include "JFunc_void_PublicationReadyEvent.hpp"
#include "JFunc_void_DecorationActivatedEvent.hpp"
#include "JFunc_void_SelectionEvent.hpp"
#include "JFunc_void_SelectionActionEvent.hpp"
#include "views/JHybridReadiumViewStateUpdater.hpp"
#include <NitroModules/DefaultConstructableObject.hpp>

namespace margelo::nitro::readium {

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

struct JHybridReadiumViewSpecImpl: public jni::JavaClass<JHybridReadiumViewSpecImpl, JHybridReadiumViewSpec::JavaPart> {
  static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativereadium/HybridReadiumView;";
  static std::shared_ptr<JHybridReadiumViewSpec> create() {
    static auto constructorFn = javaClassStatic()->getConstructor<JHybridReadiumViewSpecImpl::javaobject()>();
    jni::local_ref<JHybridReadiumViewSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
    return javaPart->getJHybridReadiumViewSpec();
  }
};

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

  // Register native JNI methods
  margelo::nitro::readium::JHybridReadiumViewSpec::CxxPart::registerNatives();
  margelo::nitro::readium::JFunc_void_Locator_cxx::registerNatives();
  margelo::nitro::readium::JFunc_void_PublicationReadyEvent_cxx::registerNatives();
  margelo::nitro::readium::JFunc_void_DecorationActivatedEvent_cxx::registerNatives();
  margelo::nitro::readium::JFunc_void_SelectionEvent_cxx::registerNatives();
  margelo::nitro::readium::JFunc_void_SelectionActionEvent_cxx::registerNatives();
  margelo::nitro::readium::views::JHybridReadiumViewStateUpdater::registerNatives();

  // Register Nitro Hybrid Objects
  HybridObjectRegistry::registerHybridObjectConstructor(
    "ReadiumView",
    []() -> std::shared_ptr<HybridObject> {
      return JHybridReadiumViewSpecImpl::create();
    }
  );
}

} // namespace margelo::nitro::readium
