#pragma once

#include <AK/String.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>
#include <LibWeb/Bindings/Request.h>

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(onmessage_getter);
    JS_DECLARE_NATIVE_FUNCTION(onmessage_setter);
    JS_DECLARE_NATIVE_FUNCTION(onmessageerror_getter);
    JS_DECLARE_NATIVE_FUNCTION(onmessageerror_setter);
    JS_DECLARE_NATIVE_FUNCTION(onerror_getter);
    JS_DECLARE_NATIVE_FUNCTION(onerror_setter);
    JS_DECLARE_NATIVE_FUNCTION(terminate);
    JS_DECLARE_NATIVE_FUNCTION(post_message);
    JS_DECLARE_NATIVE_FUNCTION(post_message0);
    JS_DECLARE_NATIVE_FUNCTION(post_message1);
};

enum class WorkerType : u8 {
    Classic,
    Module,
};

JS::ThrowCompletionOr<WorkerType> convert_to_idl_value_for_worker_type(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(WorkerType);

struct WorkerOptions {
    RequestCredentials credentials { RequestCredentials::SameOrigin };
    String name { String {} };
    WorkerType type { WorkerType::Classic };
};

JS::ThrowCompletionOr<WorkerOptions> convert_to_idl_value_for_worker_options(JS::VM&, JS::Value);

} // namespace Web::Bindings
