#pragma once

#include <AK/Optional.h>
#include <AK/Utf16String.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/InterfaceObject.h>

namespace Web::Bindings {

struct TableConstructor {
public:
    static void initialize(JS::Realm&, JS::NativeFunction&);
    static JS::ThrowCompletionOr<GC::Ref<JS::Object>> construct(InterfaceConstructor&, JS::FunctionObject&);

private:
};

struct TablePrototype {
public:
    static void initialize(JS::Realm&, JS::Object&);
    static void define_unforgeable_attributes(JS::Realm&, JS::Object&);

private:
    JS_DECLARE_NATIVE_FUNCTION(length_getter);
    JS_DECLARE_NATIVE_FUNCTION(grow);
    JS_DECLARE_NATIVE_FUNCTION(get);
    JS_DECLARE_NATIVE_FUNCTION(set);
};

enum class AddressType : u8 {
    I32,
    I64,
};

JS::ThrowCompletionOr<AddressType> convert_to_idl_value_for_address_type(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(AddressType);

enum class TableKind : u8 {
    Externref,
    Anyfunc,
};

JS::ThrowCompletionOr<TableKind> convert_to_idl_value_for_table_kind(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(TableKind);

struct TableDescriptor {
    Optional<AddressType> address {};
    TableKind element;
    JS::Value initial;
    Optional<JS::Value> maximum {};
};

JS::ThrowCompletionOr<TableDescriptor> convert_to_idl_value_for_table_descriptor(JS::VM&, JS::Value);

} // namespace Web::Bindings
