/*
 * 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 Web {
namespace ContentBlocking {
namespace FFI {

struct ContentBlockerString {
    uint8_t *data;
    size_t length;
};

extern "C" {

/// # Safety
/// - `rules` and `rules_len` must point to a valid UTF-8 string
/// - The returned pointer must be freed with `rust_content_blocker_free`
void *rust_content_blocker_create(const uint8_t *rules, size_t rules_len);

/// # Safety
/// - `engine` must be null or a valid pointer returned by `rust_content_blocker_create`
void rust_content_blocker_free(void *engine);

/// # Safety
/// - `engine` must be null or a valid pointer returned by `rust_content_blocker_create`
/// - String pointers and lengths must point to valid UTF-8 strings
bool rust_content_blocker_matches(const void *engine,
                                  const uint8_t *url,
                                  size_t url_len,
                                  const uint8_t *source_url,
                                  size_t source_url_len,
                                  const uint8_t *request_type,
                                  size_t request_type_len);

/// # Safety
/// - `engine` must be null or a valid pointer returned by `rust_content_blocker_create`
/// - String pointers and lengths must point to valid UTF-8 strings
/// - The returned string must be freed with `rust_content_blocker_free_string`
ContentBlockerString rust_content_blocker_cosmetic_css(const void *engine,
                                                       const uint8_t *url,
                                                       size_t url_len,
                                                       const uint8_t *classes,
                                                       size_t classes_len,
                                                       const uint8_t *ids,
                                                       size_t ids_len);

/// # Safety
/// - `engine` must be null or a valid pointer returned by `rust_content_blocker_create`
/// - String pointers and lengths must point to valid UTF-8 strings
bool rust_content_blocker_has_generic_cosmetic_selectors(const void *engine,
                                                         const uint8_t *url,
                                                         size_t url_len,
                                                         const uint8_t *classes,
                                                         size_t classes_len,
                                                         const uint8_t *ids,
                                                         size_t ids_len);

/// # Safety
/// - `data` and `length` must match a string returned by `rust_content_blocker_cosmetic_css`
void rust_content_blocker_free_string(uint8_t *data, size_t length);

extern uint8_t *ladybird_rust_alloc(size_t size, size_t alignment);

extern uint8_t *ladybird_rust_alloc_zeroed(size_t size, size_t alignment);

extern void ladybird_rust_dealloc(uint8_t *ptr, size_t alignment);

extern uint8_t *ladybird_rust_realloc(uint8_t *ptr, size_t old_size, size_t new_size, size_t alignment);

}  // extern "C"

}  // namespace FFI
}  // namespace ContentBlocking
}  // namespace Web
