#pragma once

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

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(ready_getter);
    JS_DECLARE_NATIVE_FUNCTION(oncontrollerchange_getter);
    JS_DECLARE_NATIVE_FUNCTION(oncontrollerchange_setter);
    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(register_);
    JS_DECLARE_NATIVE_FUNCTION(get_registration);
    JS_DECLARE_NATIVE_FUNCTION(get_registrations);
};

struct RegistrationOptions {
    Optional<String> scope {};
    WorkerType type { WorkerType::Classic };
    ServiceWorkerUpdateViaCache update_via_cache { ServiceWorkerUpdateViaCache::Imports };
};

JS::ThrowCompletionOr<RegistrationOptions> convert_to_idl_value_for_registration_options(JS::VM&, JS::Value);

} // namespace Web::Bindings
