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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(script_url_getter);
    JS_DECLARE_NATIVE_FUNCTION(state_getter);
    JS_DECLARE_NATIVE_FUNCTION(onstatechange_getter);
    JS_DECLARE_NATIVE_FUNCTION(onstatechange_setter);
    JS_DECLARE_NATIVE_FUNCTION(onerror_getter);
    JS_DECLARE_NATIVE_FUNCTION(onerror_setter);
};

enum class ServiceWorkerState : u8 {
    Parsed,
    Installing,
    Installed,
    Activating,
    Activated,
    Redundant,
};

JS::ThrowCompletionOr<ServiceWorkerState> convert_to_idl_value_for_service_worker_state(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(ServiceWorkerState);

} // namespace Web::Bindings
