#ifndef KONJURE_FFI_H
#define KONJURE_FFI_H

#pragma once

/* Generated by cbindgen from crates/konjure-ffi/src/lib.rs. Do not edit. */

#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

#define KJ_ABI_VERSION 1

typedef enum KjStatus {
  Ok = 0,
  InvalidArgument = 1,
  InvalidHandle = 2,
  BufferTooSmall = 3,
  CompileError = 4,
  RuntimeError = 5,
  InternalError = 6,
} KjStatus;

typedef struct KjHandle {
  uint32_t slot;
  uint32_t generation;
} KjHandle;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
 * Returns the ABI major version implemented by this library.
 */
uint32_t kj_abi_version(void);

/**
 * Compiles DSL source and places a generation-safe runtime handle in `out_handle`.
 *
 * # Safety
 * Non-null pointer arguments must point to readable/writable regions described by
 * their corresponding lengths. Error buffers are optional but `error_required` is required.
 */
enum KjStatus kj_runtime_compile(const uint8_t *source,
                                 size_t source_len,
                                 struct KjHandle *out_handle,
                                 uint8_t *error,
                                 size_t error_capacity,
                                 size_t *error_required);

/**
 * Creates a runtime from a serialized `SceneDocument` JSON value.
 *
 * # Safety
 * See [`kj_runtime_compile`].
 */
enum KjStatus kj_runtime_from_document_json(const uint8_t *document,
                                            size_t document_len,
                                            struct KjHandle *out_handle,
                                            uint8_t *error,
                                            size_t error_capacity,
                                            size_t *error_required);

/**
 * Disposes a runtime. A second disposal, or any stale copied handle, returns `InvalidHandle`.
 */
enum KjStatus kj_runtime_dispose(struct KjHandle handle,
                                 uint8_t *error,
                                 size_t error_capacity,
                                 size_t *error_required);

/**
 * Serializes the authoritative scene document as UTF-8 JSON.
 */
enum KjStatus kj_runtime_scene_json(struct KjHandle handle,
                                    uint8_t *output,
                                    size_t capacity,
                                    size_t *required,
                                    uint8_t *error,
                                    size_t error_capacity,
                                    size_t *error_required);

/**
 * Serializes all prepared meshes as `{ "entries": [{ "entity", "topology", "mesh" }] }` JSON.
 */
enum KjStatus kj_runtime_meshes_json(struct KjHandle handle,
                                     uint8_t *output,
                                     size_t capacity,
                                     size_t *required,
                                     uint8_t *error,
                                     size_t error_capacity,
                                     size_t *error_required);

/**
 * Samples a deterministic frame and serializes it as UTF-8 JSON.
 */
enum KjStatus kj_runtime_sample_json(struct KjHandle handle,
                                     double time_seconds,
                                     uint8_t *output,
                                     size_t capacity,
                                     size_t *required,
                                     uint8_t *error,
                                     size_t error_capacity,
                                     size_t *error_required);

/**
 * Dispatches a serialized `Event` and serializes its receipt as UTF-8 JSON.
 *
 * # Safety
 * `event` must describe a readable UTF-8 byte region of `event_len` bytes when nonempty.
 */
enum KjStatus kj_runtime_dispatch_json(struct KjHandle handle,
                                       const uint8_t *event,
                                       size_t event_len,
                                       uint8_t *output,
                                       size_t capacity,
                                       size_t *required,
                                       uint8_t *error,
                                       size_t error_capacity,
                                       size_t *error_required);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* KONJURE_FFI_H */
