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

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

#include "NitroThorOnLoad.hpp"

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

#include "JHybridThorViewSpec.hpp"
#include "views/JHybridThorViewStateUpdater.hpp"
#include <NitroModules/DefaultConstructableObject.hpp>

namespace margelo::nitro::thor {

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

struct JHybridThorViewSpecImpl: public jni::JavaClass<JHybridThorViewSpecImpl, JHybridThorViewSpec::JavaPart> {
  static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/thor/HybridThorView;";
  static std::shared_ptr<JHybridThorViewSpec> create() {
    static const auto constructorFn = javaClassStatic()->getConstructor<JHybridThorViewSpecImpl::javaobject()>();
    jni::local_ref<JHybridThorViewSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
    return javaPart->getJHybridThorViewSpec();
  }
};

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

  // Register native JNI methods
  margelo::nitro::thor::JHybridThorViewSpec::CxxPart::registerNatives();
  margelo::nitro::thor::views::JHybridThorViewStateUpdater::registerNatives();

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

} // namespace margelo::nitro::thor
