"use strict";

// Native-probe contract for jso-protector-reactnative.
//
// Pure JS inside a React Native bundle cannot read the Android/iOS
// filesystem, inspect process maps, or verify the app signing
// certificate. Those authoritative checks must come from a native
// module. This file defines the RESULT SHAPE the JS RASP engine
// consumes, plus a safe no-op default, so the engine has a stable
// contract regardless of which native implementation the host wires in
// (the bundled Kotlin/Swift stubs wrap freeRASP; a host may substitute
// its own).
//
// Wire a real probe like:
//   import { NativeModules } from "react-native";
//   const guard = createMobileGuard({ nativeProbe: () => NativeModules.JsoRasp.probe() });

// JSON-schema-ish description (documentation + the basis for any future
// validation). All fields optional; absent means "not checked".
const schema = {
    type: "object",
    properties: {
        platform:          { type: "string", enum: ["android", "ios", "unknown"] },
        isRooted:          { type: "boolean", note: "Android: su binary, Magisk, writable system paths" },
        isJailbroken:      { type: "boolean", note: "iOS: Cydia/Sileo, suspicious dylibs, sandbox escape" },
        isDebuggable:      { type: "boolean", note: "FLAG_DEBUGGABLE / ptrace attach / get-task-allow" },
        isEmulator:        { type: "boolean", note: "QEMU/Genymotion/simulator fingerprints" },
        hooksDetected:     { type: "boolean", note: "Frida, Xposed, Substrate, Shadow present" },
        signatureTampered: { type: "boolean", note: "APK/IPA signing cert does not match the expected value" },
        unofficialStore:   { type: "boolean", note: "installer package is not Play Store / App Store" },
        detectedTools:     { type: "array", items: { type: "string" }, note: "named tools, e.g. ['Magisk','Frida']" },
    },
};

// Safe default: reports nothing detected. Used when the host did not
// wire a native module — the JS-observable tripwires still run, but the
// strong signals are simply absent (verdict leans clean). Returning a
// platform of "unknown" makes "no native probe" visible in the report.
function noopProbe() {
    return { platform: "unknown" };
}

module.exports = {
    schema: schema,
    noopProbe: noopProbe,
};
