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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(onreadystatechange_getter);
    JS_DECLARE_NATIVE_FUNCTION(onreadystatechange_setter);
    JS_DECLARE_NATIVE_FUNCTION(ready_state_getter);
    JS_DECLARE_NATIVE_FUNCTION(timeout_getter);
    JS_DECLARE_NATIVE_FUNCTION(timeout_setter);
    JS_DECLARE_NATIVE_FUNCTION(with_credentials_getter);
    JS_DECLARE_NATIVE_FUNCTION(with_credentials_setter);
    JS_DECLARE_NATIVE_FUNCTION(upload_getter);
    JS_DECLARE_NATIVE_FUNCTION(response_url_getter);
    JS_DECLARE_NATIVE_FUNCTION(status_getter);
    JS_DECLARE_NATIVE_FUNCTION(status_text_getter);
    JS_DECLARE_NATIVE_FUNCTION(response_type_getter);
    JS_DECLARE_NATIVE_FUNCTION(response_type_setter);
    JS_DECLARE_NATIVE_FUNCTION(response_getter);
    JS_DECLARE_NATIVE_FUNCTION(response_text_getter);
    JS_DECLARE_NATIVE_FUNCTION(response_xml_getter);
    JS_DECLARE_NATIVE_FUNCTION(open);
    JS_DECLARE_NATIVE_FUNCTION(open0);
    JS_DECLARE_NATIVE_FUNCTION(open1);
    JS_DECLARE_NATIVE_FUNCTION(set_request_header);
    JS_DECLARE_NATIVE_FUNCTION(send);
    JS_DECLARE_NATIVE_FUNCTION(abort);
    JS_DECLARE_NATIVE_FUNCTION(get_response_header);
    JS_DECLARE_NATIVE_FUNCTION(get_all_response_headers);
    JS_DECLARE_NATIVE_FUNCTION(override_mime_type);
};

enum class XMLHttpRequestResponseType : u8 {
    Empty,
    Arraybuffer,
    Blob,
    Document,
    Json,
    Text,
};

JS::ThrowCompletionOr<XMLHttpRequestResponseType> convert_to_idl_value_for_xml_http_request_response_type(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(XMLHttpRequestResponseType);

} // namespace Web::Bindings
