#pragma once

#define AUDIOSOURCE typeid(AudioSource).name()

#include "Types.hpp"
#include "elements/AudioClip.hpp"
#include "elements/BehaviourScript.hpp"
#include "miniaudio.h"
#include <unordered_map>

namespace TSE
{
    class AudioSource : public BehaviourScript
    {
    public:
        std::unordered_map<string, AudioClip*> clips;
        string currentlyPlaying = "";

    private:
        bool global = false;
        float minDistance = 5;
        float maxDistance = 8;
        std::unordered_map<std::string, ma_sound*> sounds;

    public:
        float GetMinDistance();
        float GetMaxDistance();
        bool GetGlobal();
        void SetGlobal(bool v);
        void SetMinDistance(float v);
        void SetMaxDistance(float v);

        void AddClip(AudioClip* clip);
        void RemoveClip(std::string name);

        void StartClip(std::string name, bool forceRestart = true);
        void StopPlaying();
        void PausePlaying();
        
        AudioClip* GetClipAt(int i);

        ~AudioSource();

        void OnUpdate() override;
        inline const char* GetName() override
        {
            return "Audio Source";
        }
    };
} // namespace TSE
