 //////////////////////////////////////////////////////////
 // This file was auto-generated by tb_client_header.zig //
 //              Do not manually modify.                 //
 //////////////////////////////////////////////////////////

pub type TB_ACCOUNT_FLAGS = u16;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_LINKED: TB_ACCOUNT_FLAGS = 1 << 0;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_DEBITS_MUST_NOT_EXCEED_CREDITS: TB_ACCOUNT_FLAGS = 1 << 1;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_CREDITS_MUST_NOT_EXCEED_DEBITS: TB_ACCOUNT_FLAGS = 1 << 2;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_HISTORY: TB_ACCOUNT_FLAGS = 1 << 3;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_IMPORTED: TB_ACCOUNT_FLAGS = 1 << 4;
pub const TB_ACCOUNT_FLAGS_TB_ACCOUNT_CLOSED: TB_ACCOUNT_FLAGS = 1 << 5;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_account_t {
    pub id: u128,
    pub debits_pending: u128,
    pub debits_posted: u128,
    pub credits_pending: u128,
    pub credits_posted: u128,
    pub user_data_128: u128,
    pub user_data_64: u64,
    pub user_data_32: u32,
    pub reserved: u32,
    pub ledger: u32,
    pub code: u16,
    pub flags: u16,
    pub timestamp: u64,
}

pub type TB_TRANSFER_FLAGS = u16;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_LINKED: TB_TRANSFER_FLAGS = 1 << 0;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_PENDING: TB_TRANSFER_FLAGS = 1 << 1;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_POST_PENDING_TRANSFER: TB_TRANSFER_FLAGS = 1 << 2;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_VOID_PENDING_TRANSFER: TB_TRANSFER_FLAGS = 1 << 3;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_BALANCING_DEBIT: TB_TRANSFER_FLAGS = 1 << 4;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_BALANCING_CREDIT: TB_TRANSFER_FLAGS = 1 << 5;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_CLOSING_DEBIT: TB_TRANSFER_FLAGS = 1 << 6;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_CLOSING_CREDIT: TB_TRANSFER_FLAGS = 1 << 7;
pub const TB_TRANSFER_FLAGS_TB_TRANSFER_IMPORTED: TB_TRANSFER_FLAGS = 1 << 8;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_transfer_t {
    pub id: u128,
    pub debit_account_id: u128,
    pub credit_account_id: u128,
    pub amount: u128,
    pub pending_id: u128,
    pub user_data_128: u128,
    pub user_data_64: u64,
    pub user_data_32: u32,
    pub timeout: u32,
    pub ledger: u32,
    pub code: u16,
    pub flags: u16,
    pub timestamp: u64,
}

pub type TB_CREATE_ACCOUNT_RESULT = u32;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_OK: TB_CREATE_ACCOUNT_RESULT = 0;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_LINKED_EVENT_FAILED: TB_CREATE_ACCOUNT_RESULT = 1;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_LINKED_EVENT_CHAIN_OPEN: TB_CREATE_ACCOUNT_RESULT = 2;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_IMPORTED_EVENT_EXPECTED: TB_CREATE_ACCOUNT_RESULT = 22;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_IMPORTED_EVENT_NOT_EXPECTED: TB_CREATE_ACCOUNT_RESULT = 23;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_TIMESTAMP_MUST_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 3;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_IMPORTED_EVENT_TIMESTAMP_OUT_OF_RANGE: TB_CREATE_ACCOUNT_RESULT = 24;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_IMPORTED_EVENT_TIMESTAMP_MUST_NOT_ADVANCE: TB_CREATE_ACCOUNT_RESULT = 25;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_RESERVED_FIELD: TB_CREATE_ACCOUNT_RESULT = 4;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_RESERVED_FLAG: TB_CREATE_ACCOUNT_RESULT = 5;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_ID_MUST_NOT_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 6;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_ID_MUST_NOT_BE_INT_MAX: TB_CREATE_ACCOUNT_RESULT = 7;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_FLAGS: TB_CREATE_ACCOUNT_RESULT = 15;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_USER_DATA_128: TB_CREATE_ACCOUNT_RESULT = 16;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_USER_DATA_64: TB_CREATE_ACCOUNT_RESULT = 17;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_USER_DATA_32: TB_CREATE_ACCOUNT_RESULT = 18;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_LEDGER: TB_CREATE_ACCOUNT_RESULT = 19;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS_WITH_DIFFERENT_CODE: TB_CREATE_ACCOUNT_RESULT = 20;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_EXISTS: TB_CREATE_ACCOUNT_RESULT = 21;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_FLAGS_ARE_MUTUALLY_EXCLUSIVE: TB_CREATE_ACCOUNT_RESULT = 8;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_DEBITS_PENDING_MUST_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 9;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_DEBITS_POSTED_MUST_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 10;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_CREDITS_PENDING_MUST_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 11;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_CREDITS_POSTED_MUST_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 12;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_LEDGER_MUST_NOT_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 13;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_CODE_MUST_NOT_BE_ZERO: TB_CREATE_ACCOUNT_RESULT = 14;
pub const TB_CREATE_ACCOUNT_RESULT_TB_CREATE_ACCOUNT_IMPORTED_EVENT_TIMESTAMP_MUST_NOT_REGRESS: TB_CREATE_ACCOUNT_RESULT = 26;

pub type TB_CREATE_TRANSFER_RESULT = u32;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OK: TB_CREATE_TRANSFER_RESULT = 0;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_LINKED_EVENT_FAILED: TB_CREATE_TRANSFER_RESULT = 1;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_LINKED_EVENT_CHAIN_OPEN: TB_CREATE_TRANSFER_RESULT = 2;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_EXPECTED: TB_CREATE_TRANSFER_RESULT = 56;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_NOT_EXPECTED: TB_CREATE_TRANSFER_RESULT = 57;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_TIMESTAMP_MUST_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 3;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMESTAMP_OUT_OF_RANGE: TB_CREATE_TRANSFER_RESULT = 58;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMESTAMP_MUST_NOT_ADVANCE: TB_CREATE_TRANSFER_RESULT = 59;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_RESERVED_FLAG: TB_CREATE_TRANSFER_RESULT = 4;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_ID_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 5;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_ID_MUST_NOT_BE_INT_MAX: TB_CREATE_TRANSFER_RESULT = 6;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_FLAGS: TB_CREATE_TRANSFER_RESULT = 36;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_PENDING_ID: TB_CREATE_TRANSFER_RESULT = 40;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_TIMEOUT: TB_CREATE_TRANSFER_RESULT = 44;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_DEBIT_ACCOUNT_ID: TB_CREATE_TRANSFER_RESULT = 37;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_CREDIT_ACCOUNT_ID: TB_CREATE_TRANSFER_RESULT = 38;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_AMOUNT: TB_CREATE_TRANSFER_RESULT = 39;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_USER_DATA_128: TB_CREATE_TRANSFER_RESULT = 41;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_USER_DATA_64: TB_CREATE_TRANSFER_RESULT = 42;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_USER_DATA_32: TB_CREATE_TRANSFER_RESULT = 43;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_LEDGER: TB_CREATE_TRANSFER_RESULT = 67;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS_WITH_DIFFERENT_CODE: TB_CREATE_TRANSFER_RESULT = 45;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXISTS: TB_CREATE_TRANSFER_RESULT = 46;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_ID_ALREADY_FAILED: TB_CREATE_TRANSFER_RESULT = 68;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_FLAGS_ARE_MUTUALLY_EXCLUSIVE: TB_CREATE_TRANSFER_RESULT = 7;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_DEBIT_ACCOUNT_ID_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 8;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_DEBIT_ACCOUNT_ID_MUST_NOT_BE_INT_MAX: TB_CREATE_TRANSFER_RESULT = 9;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CREDIT_ACCOUNT_ID_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 10;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CREDIT_ACCOUNT_ID_MUST_NOT_BE_INT_MAX: TB_CREATE_TRANSFER_RESULT = 11;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_ACCOUNTS_MUST_BE_DIFFERENT: TB_CREATE_TRANSFER_RESULT = 12;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_ID_MUST_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 13;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_ID_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 14;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_ID_MUST_NOT_BE_INT_MAX: TB_CREATE_TRANSFER_RESULT = 15;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_ID_MUST_BE_DIFFERENT: TB_CREATE_TRANSFER_RESULT = 16;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_TIMEOUT_RESERVED_FOR_PENDING_TRANSFER: TB_CREATE_TRANSFER_RESULT = 17;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CLOSING_TRANSFER_MUST_BE_PENDING: TB_CREATE_TRANSFER_RESULT = 64;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_LEDGER_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 19;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CODE_MUST_NOT_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 20;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_DEBIT_ACCOUNT_NOT_FOUND: TB_CREATE_TRANSFER_RESULT = 21;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CREDIT_ACCOUNT_NOT_FOUND: TB_CREATE_TRANSFER_RESULT = 22;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_ACCOUNTS_MUST_HAVE_THE_SAME_LEDGER: TB_CREATE_TRANSFER_RESULT = 23;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_TRANSFER_MUST_HAVE_THE_SAME_LEDGER_AS_ACCOUNTS: TB_CREATE_TRANSFER_RESULT = 24;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_NOT_FOUND: TB_CREATE_TRANSFER_RESULT = 25;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_NOT_PENDING: TB_CREATE_TRANSFER_RESULT = 26;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_HAS_DIFFERENT_DEBIT_ACCOUNT_ID: TB_CREATE_TRANSFER_RESULT = 27;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_HAS_DIFFERENT_CREDIT_ACCOUNT_ID: TB_CREATE_TRANSFER_RESULT = 28;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_HAS_DIFFERENT_LEDGER: TB_CREATE_TRANSFER_RESULT = 29;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_HAS_DIFFERENT_CODE: TB_CREATE_TRANSFER_RESULT = 30;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXCEEDS_PENDING_TRANSFER_AMOUNT: TB_CREATE_TRANSFER_RESULT = 31;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_HAS_DIFFERENT_AMOUNT: TB_CREATE_TRANSFER_RESULT = 32;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_ALREADY_POSTED: TB_CREATE_TRANSFER_RESULT = 33;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_ALREADY_VOIDED: TB_CREATE_TRANSFER_RESULT = 34;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_PENDING_TRANSFER_EXPIRED: TB_CREATE_TRANSFER_RESULT = 35;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMESTAMP_MUST_NOT_REGRESS: TB_CREATE_TRANSFER_RESULT = 60;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMESTAMP_MUST_POSTDATE_DEBIT_ACCOUNT: TB_CREATE_TRANSFER_RESULT = 61;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMESTAMP_MUST_POSTDATE_CREDIT_ACCOUNT: TB_CREATE_TRANSFER_RESULT = 62;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_IMPORTED_EVENT_TIMEOUT_MUST_BE_ZERO: TB_CREATE_TRANSFER_RESULT = 63;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_DEBIT_ACCOUNT_ALREADY_CLOSED: TB_CREATE_TRANSFER_RESULT = 65;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_CREDIT_ACCOUNT_ALREADY_CLOSED: TB_CREATE_TRANSFER_RESULT = 66;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_DEBITS_PENDING: TB_CREATE_TRANSFER_RESULT = 47;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_CREDITS_PENDING: TB_CREATE_TRANSFER_RESULT = 48;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_DEBITS_POSTED: TB_CREATE_TRANSFER_RESULT = 49;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_CREDITS_POSTED: TB_CREATE_TRANSFER_RESULT = 50;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_DEBITS: TB_CREATE_TRANSFER_RESULT = 51;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_CREDITS: TB_CREATE_TRANSFER_RESULT = 52;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_OVERFLOWS_TIMEOUT: TB_CREATE_TRANSFER_RESULT = 53;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXCEEDS_CREDITS: TB_CREATE_TRANSFER_RESULT = 54;
pub const TB_CREATE_TRANSFER_RESULT_TB_CREATE_TRANSFER_EXCEEDS_DEBITS: TB_CREATE_TRANSFER_RESULT = 55;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_create_accounts_result_t {
    pub index: u32,
    pub result: u32,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_create_transfers_result_t {
    pub index: u32,
    pub result: u32,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_account_filter_t {
    pub account_id: u128,
    pub user_data_128: u128,
    pub user_data_64: u64,
    pub user_data_32: u32,
    pub code: u16,
    pub reserved: [u8; 58],
    pub timestamp_min: u64,
    pub timestamp_max: u64,
    pub limit: u32,
    pub flags: u32,
}

pub type TB_ACCOUNT_FILTER_FLAGS = u32;
pub const TB_ACCOUNT_FILTER_FLAGS_TB_ACCOUNT_FILTER_DEBITS: TB_ACCOUNT_FILTER_FLAGS = 1 << 0;
pub const TB_ACCOUNT_FILTER_FLAGS_TB_ACCOUNT_FILTER_CREDITS: TB_ACCOUNT_FILTER_FLAGS = 1 << 1;
pub const TB_ACCOUNT_FILTER_FLAGS_TB_ACCOUNT_FILTER_REVERSED: TB_ACCOUNT_FILTER_FLAGS = 1 << 2;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_account_balance_t {
    pub debits_pending: u128,
    pub debits_posted: u128,
    pub credits_pending: u128,
    pub credits_posted: u128,
    pub timestamp: u64,
    pub reserved: [u8; 56],
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_query_filter_t {
    pub user_data_128: u128,
    pub user_data_64: u64,
    pub user_data_32: u32,
    pub ledger: u32,
    pub code: u16,
    pub reserved: [u8; 6],
    pub timestamp_min: u64,
    pub timestamp_max: u64,
    pub limit: u32,
    pub flags: u32,
}

pub type TB_QUERY_FILTER_FLAGS = u32;
pub const TB_QUERY_FILTER_FLAGS_TB_QUERY_FILTER_REVERSED: TB_QUERY_FILTER_FLAGS = 1 << 0;

// Opaque struct serving as a handle for the client instance.
// This struct must be "pinned" (not copyable or movable), as its address must remain stable
// throughout the lifetime of the client instance.
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_client_t {
    pub opaque: [u64; 4],
}

// Struct containing the state of a request submitted through the client.
// This struct must be "pinned" (not copyable or movable), as its address must remain stable
// throughout the lifetime of the request.
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct tb_packet_t {
    pub user_data: *mut ::std::os::raw::c_void,
    pub data: *mut ::std::os::raw::c_void,
    pub data_size: u32,
    pub user_tag: u16,
    pub operation: u8,
    pub status: u8,
    pub opaque: [u8; 64],
}

pub type TB_OPERATION = u8;
pub const TB_OPERATION_TB_OPERATION_PULSE: TB_OPERATION = 128;
pub const TB_OPERATION_TB_OPERATION_GET_CHANGE_EVENTS: TB_OPERATION = 137;
pub const TB_OPERATION_TB_OPERATION_CREATE_ACCOUNTS: TB_OPERATION = 138;
pub const TB_OPERATION_TB_OPERATION_CREATE_TRANSFERS: TB_OPERATION = 139;
pub const TB_OPERATION_TB_OPERATION_LOOKUP_ACCOUNTS: TB_OPERATION = 140;
pub const TB_OPERATION_TB_OPERATION_LOOKUP_TRANSFERS: TB_OPERATION = 141;
pub const TB_OPERATION_TB_OPERATION_GET_ACCOUNT_TRANSFERS: TB_OPERATION = 142;
pub const TB_OPERATION_TB_OPERATION_GET_ACCOUNT_BALANCES: TB_OPERATION = 143;
pub const TB_OPERATION_TB_OPERATION_QUERY_ACCOUNTS: TB_OPERATION = 144;
pub const TB_OPERATION_TB_OPERATION_QUERY_TRANSFERS: TB_OPERATION = 145;

pub type TB_PACKET_STATUS = u8;
pub const TB_PACKET_STATUS_TB_PACKET_OK: TB_PACKET_STATUS = 0;
pub const TB_PACKET_STATUS_TB_PACKET_TOO_MUCH_DATA: TB_PACKET_STATUS = 1;
pub const TB_PACKET_STATUS_TB_PACKET_CLIENT_EVICTED: TB_PACKET_STATUS = 2;
pub const TB_PACKET_STATUS_TB_PACKET_CLIENT_RELEASE_TOO_LOW: TB_PACKET_STATUS = 3;
pub const TB_PACKET_STATUS_TB_PACKET_CLIENT_RELEASE_TOO_HIGH: TB_PACKET_STATUS = 4;
pub const TB_PACKET_STATUS_TB_PACKET_CLIENT_SHUTDOWN: TB_PACKET_STATUS = 5;
pub const TB_PACKET_STATUS_TB_PACKET_INVALID_OPERATION: TB_PACKET_STATUS = 6;
pub const TB_PACKET_STATUS_TB_PACKET_INVALID_DATA_SIZE: TB_PACKET_STATUS = 7;

pub type TB_INIT_STATUS = i32;
pub const TB_INIT_STATUS_TB_INIT_SUCCESS: TB_INIT_STATUS = 0;
pub const TB_INIT_STATUS_TB_INIT_UNEXPECTED: TB_INIT_STATUS = 1;
pub const TB_INIT_STATUS_TB_INIT_OUT_OF_MEMORY: TB_INIT_STATUS = 2;
pub const TB_INIT_STATUS_TB_INIT_ADDRESS_INVALID: TB_INIT_STATUS = 3;
pub const TB_INIT_STATUS_TB_INIT_ADDRESS_LIMIT_EXCEEDED: TB_INIT_STATUS = 4;
pub const TB_INIT_STATUS_TB_INIT_SYSTEM_RESOURCES: TB_INIT_STATUS = 5;
pub const TB_INIT_STATUS_TB_INIT_NETWORK_SUBSYSTEM: TB_INIT_STATUS = 6;

pub type TB_CLIENT_STATUS = i32;
pub const TB_CLIENT_STATUS_TB_CLIENT_OK: TB_CLIENT_STATUS = 0;
pub const TB_CLIENT_STATUS_TB_CLIENT_INVALID: TB_CLIENT_STATUS = 1;

pub type TB_REGISTER_LOG_CALLBACK_STATUS = i32;
pub const TB_REGISTER_LOG_CALLBACK_STATUS_TB_REGISTER_LOG_CALLBACK_SUCCESS: TB_REGISTER_LOG_CALLBACK_STATUS = 0;
pub const TB_REGISTER_LOG_CALLBACK_STATUS_TB_REGISTER_LOG_CALLBACK_ALREADY_REGISTERED: TB_REGISTER_LOG_CALLBACK_STATUS = 1;
pub const TB_REGISTER_LOG_CALLBACK_STATUS_TB_REGISTER_LOG_CALLBACK_NOT_REGISTERED: TB_REGISTER_LOG_CALLBACK_STATUS = 2;

pub type TB_LOG_LEVEL = i32;
pub const TB_LOG_LEVEL_TB_LOG_ERR: TB_LOG_LEVEL = 0;
pub const TB_LOG_LEVEL_TB_LOG_WARN: TB_LOG_LEVEL = 1;
pub const TB_LOG_LEVEL_TB_LOG_INFO: TB_LOG_LEVEL = 2;
pub const TB_LOG_LEVEL_TB_LOG_DEBUG: TB_LOG_LEVEL = 3;

extern "C" {
    // Initialize a new TigerBeetle client which connects to the addresses provided and
    // completes submitted packets by invoking the callback with the given context.
    pub fn tb_client_init(
        client_out: *mut tb_client_t,
        // 128-bit unsigned integer represented as a 16-byte little-endian array.
        cluster_id: *const [u8; 16],
        address_ptr: *const ::std::os::raw::c_char,
        address_len: u32,
        completion_ctx: usize,
        completion_callback: ::std::option::Option<
            unsafe extern "C" fn(
                arg1: usize,
                arg3: *mut tb_packet_t,
                arg4: u64,
                arg5: *const u8,
                arg6: u32,
            ),
        >,
    ) -> TB_INIT_STATUS;

    // Initialize a new TigerBeetle client which echos back any data submitted.
    pub fn tb_client_init_echo(
        client_out: *mut tb_client_t,
        // 128-bit unsigned integer represented as a 16-byte little-endian array.
        cluster_id: *const [u8; 16],
        address_ptr: *const ::std::os::raw::c_char,
        address_len: u32,
        completion_ctx: usize,
        completion_callback: ::std::option::Option<
            unsafe extern "C" fn(
                arg1: usize,
                arg3: *mut tb_packet_t,
                arg4: u64,
                arg5: *const u8,
                arg6: u32,
            ),
        >,
    ) -> TB_INIT_STATUS;

    // Retrieve the callback context initially passed into `tb_client_init` or
    // `tb_client_init_echo`.
    pub fn tb_client_completion_context(
        client: *mut tb_client_t,
        completion_ctx_out: *mut usize,
    ) -> TB_CLIENT_STATUS;

    // Submit a packet with its operation, data, and data_size fields set.
    // Once completed, `on_completion` will be invoked with `on_completion_ctx` and the given
    // packet on the `tb_client` thread (separate from caller's thread).
    pub fn tb_client_submit(
        client: *mut tb_client_t,
        packet: *mut tb_packet_t,
    ) -> TB_CLIENT_STATUS;

    // Closes the client, causing any previously submitted packets to be completed with
    // `TB_PACKET_CLIENT_SHUTDOWN` before freeing any allocated client resources from init.
    // It is undefined behavior to use any functions on the client once deinit is called.
    pub fn tb_client_deinit(
        client: *mut tb_client_t,
    ) -> TB_CLIENT_STATUS;

    // Registers or unregisters the application log callback.
    pub fn register_log_callback(
        callback: ::std::option::Option<
            unsafe extern "C" fn(
                TB_LOG_LEVEL,
                *const u8,
                u32,
            ),
        >,
        debug: bool,
    ) -> TB_REGISTER_LOG_CALLBACK_STATUS;
}