/* Auto-generated by cbindgen. Do not edit. */

#ifndef HEERANJID_H
#define HEERANJID_H

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

/**
 * HeerId is represented as a plain i64 across the FFI boundary.
 */
typedef int64_t HeerIdT;

/**
 * RanjId is represented as 16 raw UUID bytes across the FFI boundary.
 */
typedef struct RanjIdT {
    uint8_t bytes[16];
} RanjIdT;

/**
 * Returns 0 if no error is stored.
 * Otherwise copies the last error message into `buf` (up to `buf_len` bytes
 * including the NUL terminator) and returns the number of bytes written
 * (excluding the NUL). If the buffer is too small the message is truncated.
 *
 * # Safety
 *
 * `buf` must point to a writable buffer of at least `buf_len` bytes, or be null.
 */
int heer_last_error(char *buf, int buf_len);

/**
 * Decode a HeerId into its component parts.
 * Returns 0 on success, -1 on error (check `heer_last_error`).
 *
 * # Safety
 *
 * Output pointers must be valid or null. Null pointers are safely skipped.
 */
int heer_id_decode(HeerIdT id, uint64_t *timestamp_ms, uint16_t *node_id, uint16_t *sequence);

/**
 * Convert a HeerId to its string representation.
 * Writes into `buf` (up to `buf_len` bytes including NUL).
 * Returns the number of bytes written (excluding NUL) on success, -1 on error.
 *
 * # Safety
 *
 * `buf` must point to a writable buffer of at least `buf_len` bytes, or be null.
 */
int heer_id_to_string(HeerIdT id, char *buf, int buf_len);

/**
 * Parse a HeerId from a NUL-terminated string.
 * On success writes the result into `*out` and returns 0.
 * On error returns -1.
 *
 * # Safety
 *
 * `s` must be a valid NUL-terminated C string. `out` must be a valid pointer.
 */
int heer_id_from_string(const char *s, HeerIdT *out);

/**
 * Decode a RanjId into its component parts.
 * Returns 0 on success, -1 on error.
 *
 * # Safety
 *
 * `id` must point to a valid `RanjIdT`. Output pointers must be valid or null.
 */
int ranj_id_decode(const struct RanjIdT *id,
                   uint64_t *timestamp_us,
                   uint16_t *node_id,
                   uint16_t *sequence);

/**
 * Convert a RanjId to its UUID string representation.
 * Writes into `buf` (up to `buf_len` bytes including NUL).
 * Returns bytes written (excluding NUL) on success, -1 on error.
 *
 * # Safety
 *
 * `id` must point to a valid `RanjIdT`. `buf` must be writable for `buf_len` bytes.
 */
int ranj_id_to_string(const struct RanjIdT *id, char *buf, int buf_len);

/**
 * Parse a RanjId from a NUL-terminated UUID string.
 * On success writes the result into `*out` and returns 0.
 * On error returns -1.
 *
 * # Safety
 *
 * `s` must be a valid NUL-terminated C string. `out` must be a valid pointer.
 */
int ranj_id_from_string(const char *s, struct RanjIdT *out);

#endif  /* HEERANJID_H */
