#![deny(missing_debug_implementations)]

use std::ffi::c_char;

use jni::objects::JClass;
use jni::sys::jstring;
use jni::JNIEnv;

static CORE_VERSION: &[u8] = concat!(env!("CARGO_PKG_VERSION"), "\0").as_bytes();

/// C ABI entrypoint for platform shells that do not use JNI.
#[no_mangle]
pub extern "C" fn burrow_core_version() -> *const c_char {
    CORE_VERSION.as_ptr().cast()
}

/// JNI entrypoint used by the Android Kotlin stub.
#[no_mangle]
pub extern "system" fn Java_net_burrow_android_BurrowCore_version(
    env: JNIEnv<'_>,
    _class: JClass<'_>,
) -> jstring {
    match env.new_string(burrow_core::identity()) {
        Ok(value) => value.into_raw(),
        Err(_) => std::ptr::null_mut(),
    }
}
