#pragma once

#include <AK/Optional.h>
#include <AK/Utf16String.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/AudioNode.h>
#include <LibWeb/Bindings/InterfaceObject.h>
#include <LibWeb/Forward.h>

namespace Web::Bindings {

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

private:
};

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

private:
    JS_DECLARE_NATIVE_FUNCTION(type_getter);
    JS_DECLARE_NATIVE_FUNCTION(type_setter);
    JS_DECLARE_NATIVE_FUNCTION(frequency_getter);
    JS_DECLARE_NATIVE_FUNCTION(detune_getter);
    JS_DECLARE_NATIVE_FUNCTION(set_periodic_wave);
};

enum class OscillatorType : u8 {
    Sine,
    Square,
    Sawtooth,
    Triangle,
    Custom,
};

JS::ThrowCompletionOr<OscillatorType> convert_to_idl_value_for_oscillator_type(JS::VM&, JS::Value);

Utf16String idl_enum_to_string(OscillatorType);

struct OscillatorOptions : public AudioNodeOptions {
    float detune { 0 };
    float frequency { 440 };
    GC::Ptr<WebAudio::PeriodicWave> periodic_wave {};
    OscillatorType type { OscillatorType::Sine };
};

JS::ThrowCompletionOr<OscillatorOptions> convert_to_idl_value_for_oscillator_options(JS::VM&, JS::Value);

} // namespace Web::Bindings
