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

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

#include "NitroMmfileOnLoad.hpp"

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

#include "JHybridMmfilePlatformContextSpec.hpp"
#include "HybridMmfilePackage.hpp"
#include <NitroModules/DefaultConstructableObject.hpp>

namespace margelo::nitro::mmfile {

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

struct JHybridMmfilePlatformContextSpecImpl: public jni::JavaClass<JHybridMmfilePlatformContextSpecImpl, JHybridMmfilePlatformContextSpec::JavaPart> {
  static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/mmfile/HybridMmfilePlatformContext;";
  static std::shared_ptr<JHybridMmfilePlatformContextSpec> create() {
    static const auto constructorFn = javaClassStatic()->getConstructor<JHybridMmfilePlatformContextSpecImpl::javaobject()>();
    jni::local_ref<JHybridMmfilePlatformContextSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
    return javaPart->getJHybridMmfilePlatformContextSpec();
  }
};

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

  // Register native JNI methods
  margelo::nitro::mmfile::JHybridMmfilePlatformContextSpec::CxxPart::registerNatives();

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

} // namespace margelo::nitro::mmfile
