﻿/**
 * Justified Systems - C-ABI Native Substrate Export Header
 * Module: web_canvas/docs/snippets/justified_oem_cabi.h
 * Governance: [JEF-SPEC-09.03.000], [JEF-DIST-07.02.000], [JUS-ENG-v1.0.0],
 *              [JUS-WEB-SPEC-v1.0.0-ADDENDUM-18], [JUS-WEB-SPEC-v1.0.0-ADDENDUM-27]
 */

#ifndef JUSTIFIED_OEM_CABI_H
#define JUSTIFIED_OEM_CABI_H

#ifdef __cplusplus
extern "C" {
#endif

/* Dynamic Library Import/Export Macros */
#if defined(_WIN32) || defined(_WIN64)
  #if defined(JUSTIFIED_CORE_EXPORTS)
    #define JEF_API __declspec(dllexport)
  #else
    #define JEF_API __declspec(dllimport)
  #endif
  #define JEF_CALL __cdecl
#else
  #if defined(JUSTIFIED_CORE_EXPORTS)
    #define JEF_API __attribute__((visibility("default")))
  #else
    #define JEF_API
  #endif
  #define JEF_CALL
#endif

/* Status & Deterministic Error Codes */
#define JEF_SUCCESS                    0
#define JEF_ERR_INVALID_LICENSE       -1
#define JEF_ERR_CERT_PINNING_FAIL     -2
#define JEF_ERR_MODEL_LOAD_FAIL       -3
#define JEF_ERR_BUFFER_OVERFLOW       -4
#define JEF_ERR_INSUFFICIENT_VRAM     -5
#define JEF_ERR_SYNTAX_CLAMP_FAIL     -6
#define JEF_ERR_NOT_INITIALIZED       -7

/**
 * Initializes the Justified micro-kernel engine in silent B2B OEM in-process mode.
 * Verified 100% offline via asymmetric Ed25519 digital signature attestation.
 * Zero hardware fingerprinting, zero rolling expiration time-bombs, zero network egress.
 *
 * @param model_path Path to GGUF model weights or .jef_bin companion vault.
 * @param license_file_or_token Path to license.key file coordinate or raw offline Ed25519 token.
 * @param cert_thumbprint Optional SHA-256 certificate thumbprint of calling parent (or NULL for unrestricted offline attestation per Addendum 18).
 * @returns JEF_SUCCESS (0) on successful verification, or negative error code on failure.
 */
JEF_API int JEF_CALL Justified_InitOEM(const char* model_path, const char* license_file_or_token, const char* cert_thumbprint);

/**
 * Executes a single-line NDJSON forward pass over native C memory.
 *
 * @param input_json Single-line null-terminated NDJSON prompt string.
 * @param output_buffer Pre-allocated char buffer to receive the output response.
 * @param buffer_size Maximum capacity in bytes of output_buffer (including null terminator).
 * @returns Bytes written to output_buffer (excluding null terminator), or negative error code.
 */
JEF_API int JEF_CALL Justified_ExecuteInference(const char* input_json, char* output_buffer, int buffer_size);

/**
 * Flushes transient context buffers and cleanly shuts down the in-process inference substrate.
 * Releases pinned accelerator memory, transformer layer caches, and mutex gates.
 * Matches authoritative compiled symbol table [JUS-WEB-SPEC-v1.0.0-ADDENDUM-27].
 *
 * @returns JEF_SUCCESS (0) on complete deallocation.
 */
JEF_API int JEF_CALL Justified_Free(void);

/* Inline convenience alias for Justified_Free */
static inline int Justified_ShutdownOEM(void) {
    return Justified_Free();
}

#ifdef __cplusplus
}
#endif

#endif /* JUSTIFIED_OEM_CABI_H */