#pragma once

#include <vector>
#include <filesystem>

#include <miniaudio/miniaudio.h>

struct DecoderState {
    ma_decoder decoder{};
    bool is_finished = false;
    ma_decoder_config m_decoder_config{};
};

class Audio {
    
private:
    ma_device m_device{};
    ma_device_config m_device_config{};

    DecoderState m_decoder{};


    std::vector<std::filesystem::path> m_loaded_files = std::vector<std::filesystem::path>();
    std::filesystem::path m_selected_file = std::filesystem::path();
    size_t m_selected_file_idx = 0;
    bool m_is_playing = false;

    static void data_callback(ma_device* device, void* output, const void* input, ma_uint32 frame_count);

public:
    Audio();
    ~Audio();

    void load_file(std::filesystem::path file_path);
    void play();
    void stop();
    void select_file(std::filesystem::path file);
    bool is_playing() { return m_is_playing; }
    void next_music();
    DecoderState decoder() { return m_decoder; }



    std::vector<std::filesystem::path> loaded_files();
};