/*
 * Copyright (c) 2026-present, the Ladybird developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

/* Generated with cbindgen:0.29.2 */

#include <stdint.h>
#include <stddef.h>

namespace TextCodec {
namespace FFI {

struct TextCodecRustStreamingDecoder;

using FfiBytesFn = void(*)(void *ctx, const uint8_t *data, size_t len);

using FfiCodePointFn = void(*)(void *ctx, uint32_t code_point);

extern "C" {

/// # Safety
/// - `label`/`label_len` must be a valid byte slice.
/// - `out_name` and `out_name_len` must be valid writable pointers.
bool textcodec_rust_get_standardized_encoding(const uint8_t *label,
                                              size_t label_len,
                                              const uint8_t **out_name,
                                              size_t *out_name_len);

/// # Safety
/// - `encoding_label`/`encoding_label_len` and `input`/`input_len` must be valid byte slices.
/// - `on_bytes` must not retain `data` beyond the duration of the callback.
bool textcodec_rust_decode_to_utf8(const uint8_t *encoding_label,
                                   size_t encoding_label_len,
                                   const uint8_t *input,
                                   size_t input_len,
                                   bool remove_bom,
                                   bool fatal,
                                   void *ctx,
                                   FfiBytesFn on_bytes);

/// # Safety
/// - `encoding_label`/`encoding_label_len` must be a valid byte slice.
/// - The returned pointer must be freed with `textcodec_rust_streaming_decoder_free`.
TextCodecRustStreamingDecoder *textcodec_rust_streaming_decoder_new(const uint8_t *encoding_label,
                                                                    size_t encoding_label_len,
                                                                    bool remove_bom);

/// # Safety
/// - `decoder` must be null or a pointer returned by `textcodec_rust_streaming_decoder_new`.
void textcodec_rust_streaming_decoder_free(TextCodecRustStreamingDecoder *decoder);

/// # Safety
/// - `decoder` must be a valid pointer returned by `textcodec_rust_streaming_decoder_new`.
/// - `input`/`input_len` must be a valid byte slice.
/// - `on_bytes` must not retain `data` beyond the duration of the callback.
bool textcodec_rust_streaming_decoder_decode_to_utf8(TextCodecRustStreamingDecoder *decoder,
                                                     const uint8_t *input,
                                                     size_t input_len,
                                                     bool last,
                                                     bool fatal,
                                                     void *ctx,
                                                     FfiBytesFn on_bytes);

/// # Safety
/// - `encoding_label`/`encoding_label_len` and `input`/`input_len` must be valid byte slices.
/// - `on_bytes` and `on_error` must not retain data beyond their callback duration.
bool textcodec_rust_encode_from_utf8(const uint8_t *encoding_label,
                                     size_t encoding_label_len,
                                     const uint8_t *input,
                                     size_t input_len,
                                     void *ctx,
                                     FfiBytesFn on_bytes,
                                     FfiCodePointFn on_error);

}  // extern "C"

}  // namespace FFI
}  // namespace TextCodec
