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

struct FfiCalendarDate {
    int32_t year;
    uint8_t month;
    uint8_t month_code[5];
    uint8_t month_code_length;
    uint8_t day;
    uint8_t day_of_week;
    uint16_t day_of_year;
    uint8_t days_in_week;
    uint8_t days_in_month;
    uint16_t days_in_year;
    uint8_t months_in_year;
    bool in_leap_year;
};

struct FfiISODate {
    int32_t year;
    uint8_t month;
    uint8_t day;
};

struct FfiOptionalISODate {
    FfiISODate iso_date;
    bool has_value;
};

extern "C" {

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);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
FfiCalendarDate icu_iso_date_to_calendar_date(const uint8_t *calendar,
                                              size_t calendar_length,
                                              int32_t iso_year,
                                              uint8_t iso_month,
                                              uint8_t iso_day);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
FfiOptionalISODate icu_calendar_date_to_iso_date(const uint8_t *calendar,
                                                 size_t calendar_length,
                                                 int32_t arithmetic_year,
                                                 uint8_t ordinal_month,
                                                 uint8_t day);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
/// `month_code` must point to a valid UTF-8 string of `month_code_length` bytes.
FfiOptionalISODate icu_iso_year_and_month_code_to_iso_date(const uint8_t *calendar,
                                                           size_t calendar_length,
                                                           int32_t iso_year,
                                                           const uint8_t *month_code,
                                                           size_t month_code_length,
                                                           uint8_t day);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
/// `month_code` must point to a valid UTF-8 string of `month_code_length` bytes.
FfiOptionalISODate icu_calendar_year_and_month_code_to_iso_date(const uint8_t *calendar,
                                                                size_t calendar_length,
                                                                int32_t arithmetic_year,
                                                                const uint8_t *month_code,
                                                                size_t month_code_length,
                                                                uint8_t day);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
uint8_t icu_calendar_months_in_year(const uint8_t *calendar, size_t calendar_length, int32_t arithmetic_year);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
uint8_t icu_calendar_days_in_month(const uint8_t *calendar,
                                   size_t calendar_length,
                                   int32_t arithmetic_year,
                                   uint8_t ordinal_month);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
/// `month_code` must point to a valid UTF-8 string of `month_code_length` bytes.
uint8_t icu_calendar_max_days_in_month_code(const uint8_t *calendar,
                                            size_t calendar_length,
                                            const uint8_t *month_code,
                                            size_t month_code_length);

/// # Safety
/// `calendar` must point to a valid UTF-8 string of `calendar_length` bytes.
/// `month_code` must point to a valid UTF-8 string of `month_code_length` bytes.
bool icu_year_contains_month_code(const uint8_t *calendar,
                                  size_t calendar_length,
                                  int32_t arithmetic_year,
                                  const uint8_t *month_code,
                                  size_t month_code_length);

extern bool unicode_property_matches(uint32_t code_point,
                                     const uint8_t *name_ptr,
                                     size_t name_len,
                                     const uint8_t *value_ptr,
                                     size_t value_len);

extern bool unicode_property_matches_case_insensitive(uint32_t code_point,
                                                      const uint8_t *name_ptr,
                                                      size_t name_len,
                                                      const uint8_t *value_ptr,
                                                      size_t value_len);

extern bool unicode_property_all_case_equivalents_match(uint32_t code_point,
                                                        const uint8_t *name_ptr,
                                                        size_t name_len,
                                                        const uint8_t *value_ptr,
                                                        size_t value_len);

extern bool unicode_resolve_property(const uint8_t *name_ptr,
                                     size_t name_len,
                                     const uint8_t *value_ptr,
                                     size_t value_len,
                                     uint8_t *out_kind,
                                     uint32_t *out_id);

extern bool unicode_resolved_property_matches(uint32_t code_point, uint8_t kind, uint32_t id);

extern bool unicode_code_point_has_space_separator_general_category(uint32_t code_point);

extern bool unicode_code_point_has_identifier_start_property(uint32_t code_point);

extern bool unicode_code_point_has_identifier_continue_property(uint32_t code_point);

extern bool unicode_is_string_property(const uint8_t *name_ptr, size_t name_len);

extern bool unicode_is_valid_ecma262_property(const uint8_t *name_ptr,
                                              size_t name_len,
                                              const uint8_t *value_ptr,
                                              size_t value_len);

extern uint32_t unicode_get_string_property_data(const uint8_t *name_ptr,
                                                 size_t name_len,
                                                 uint32_t *out,
                                                 uint32_t capacity);

extern uint32_t unicode_simple_case_fold(uint32_t code_point, bool unicode_mode);

extern bool unicode_code_point_matches_range_ignoring_case(uint32_t code_point,
                                                           uint32_t from,
                                                           uint32_t to,
                                                           bool unicode_mode);

extern uint32_t unicode_get_case_closure(uint32_t code_point, uint32_t *out_buffer, uint32_t buffer_capacity);

}  // extern "C"

}  // namespace FFI
}  // namespace Unicode
