#pragma once

#include <AK/Optional.h>
#include <LibGC/Ptr.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/Forward.h>

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(buffer_getter);
    JS_DECLARE_NATIVE_FUNCTION(buffer_setter);
    JS_DECLARE_NATIVE_FUNCTION(playback_rate_getter);
    JS_DECLARE_NATIVE_FUNCTION(detune_getter);
    JS_DECLARE_NATIVE_FUNCTION(loop_getter);
    JS_DECLARE_NATIVE_FUNCTION(loop_setter);
    JS_DECLARE_NATIVE_FUNCTION(loop_start_getter);
    JS_DECLARE_NATIVE_FUNCTION(loop_start_setter);
    JS_DECLARE_NATIVE_FUNCTION(loop_end_getter);
    JS_DECLARE_NATIVE_FUNCTION(loop_end_setter);
    JS_DECLARE_NATIVE_FUNCTION(start);
};

struct AudioBufferSourceOptions {
    Optional<GC::Ptr<WebAudio::AudioBuffer>> buffer {};
    float detune { 0 };
    bool loop { false };
    double loop_end { 0 };
    double loop_start { 0 };
    float playback_rate { 1 };
};

JS::ThrowCompletionOr<AudioBufferSourceOptions> convert_to_idl_value_for_audio_buffer_source_options(JS::VM&, JS::Value);

} // namespace Web::Bindings
