package com.humand.demo.modules.JSIInstaller
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.common.annotations.FrameworkAPI

class JSIInstallerModule(private val reactContext: ReactApplicationContext) :
        ReactContextBaseJavaModule(reactContext){

    override fun getName(): String {
        return NAME
    }

    companion object {
        const val NAME = "JSIInstallerModule"
        init {
            System.loadLibrary("appmodules")
        }

        @OptIn(FrameworkAPI::class)
        @JvmStatic
        private external fun nativeInstall(jsiRuntimePtr: Long)
    }

    @ReactMethod(isBlockingSynchronousMethod = true)
    fun install(): Boolean {
        nativeInstall(
            reactContext.javaScriptContextHolder!!.get(),
        )
        return true
    }
}
