#pragma once

#include <AK/Optional.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>
#include <LibWeb/WebIDL/Types.h>

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(buffer_getter);
    JS_DECLARE_NATIVE_FUNCTION(grow);
    JS_DECLARE_NATIVE_FUNCTION(to_fixed_length_buffer);
    JS_DECLARE_NATIVE_FUNCTION(to_resizable_buffer);
};

struct MemoryDescriptor {
    WebIDL::UnsignedLong initial;
    Optional<WebIDL::UnsignedLong> maximum {};
    bool shared { false };
};

JS::ThrowCompletionOr<MemoryDescriptor> convert_to_idl_value_for_memory_descriptor(JS::VM&, JS::Value);

} // namespace Web::Bindings
