#pragma once

#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>

namespace poe2::platform {

enum class SoundType {
    AttachSuccess,
    PanicRestore,
    BrickAlert,
    ToggleOn,
    ToggleOff
};

class SoundEffects {
public:
    static SoundEffects& Instance() {
        static SoundEffects inst;
        return inst;
    }

    void SetEnabled(bool enabled) noexcept { enabled_.store(enabled, std::memory_order_relaxed); }
    bool IsEnabled() const noexcept { return enabled_.load(std::memory_order_relaxed); }

    void PlayAttachSuccess();
    void PlayPanicRestore();
    void PlayBrickAlert();
    void PlayToggle(bool isOn);

    void Stop();

private:
    SoundEffects();
    ~SoundEffects();

    void EnqueueSound(SoundType type);
    void WorkerLoop();

    std::atomic<bool> enabled_{true};
    std::atomic<bool> running_{true};
    std::mutex mutex_;
    std::condition_variable cv_;
    std::queue<SoundType> queue_;
    std::thread worker_;
};

} // namespace poe2::platform

