#pragma once

#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 GlobalConstructor {
public:
    static void initialize(JS::Realm&, JS::NativeFunction&);
    static JS::ThrowCompletionOr<GC::Ref<JS::Object>> construct(InterfaceConstructor&, JS::FunctionObject&);

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(value_getter);
    JS_DECLARE_NATIVE_FUNCTION(value_setter);
    JS_DECLARE_NATIVE_FUNCTION(value_of);
};

enum class ValueType : u8 {
    I32,
    I64,
    F32,
    F64,
    V128,
    Externref,
    Anyfunc,
};

JS::ThrowCompletionOr<ValueType> convert_to_idl_value_for_value_type(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(ValueType);

struct GlobalDescriptor {
    bool mutable_ { false };
    ValueType value;
};

JS::ThrowCompletionOr<GlobalDescriptor> convert_to_idl_value_for_global_descriptor(JS::VM&, JS::Value);

} // namespace Web::Bindings
