#pragma once

#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Variant.h>
#include <LibGC/Ptr.h>
#include <LibGC/RootVector.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/Event.h>
#include <LibWeb/Bindings/InterfaceObject.h>
#include <LibWeb/Forward.h>

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(data_getter);
    JS_DECLARE_NATIVE_FUNCTION(origin_getter);
    JS_DECLARE_NATIVE_FUNCTION(last_event_id_getter);
    JS_DECLARE_NATIVE_FUNCTION(source_getter);
    JS_DECLARE_NATIVE_FUNCTION(ports_getter);
    JS_DECLARE_NATIVE_FUNCTION(init_message_event);
};

struct MessageEventInit : public EventInit {
    JS::Value data { JS::js_null() };
    String last_event_id { String {} };
    String origin { String {} };
    GC::RootVector<GC::Ref<HTML::MessagePort>> ports { GC::RootVector<GC::Ref<HTML::MessagePort>> {} };
    Variant<GC::Ref<HTML::WindowProxy>, GC::Ref<HTML::MessagePort>, Empty> source { Variant<GC::Ref<HTML::WindowProxy>, GC::Ref<HTML::MessagePort>, Empty> { Empty {} } };
};

JS::ThrowCompletionOr<MessageEventInit> convert_to_idl_value_for_message_event_init(JS::VM&, JS::Value);

} // namespace Web::Bindings
