#ifndef AUDIO_SOURCE_HPP_
#define AUDIO_SOURCE_HPP_

#include <vector>

#include <Utilities/Extern.hpp>
#include <Sound/Sound.hpp>

/**
 * @brief Represents an audio source in 3D space.
 */
class AudioSource
{
private:
    ALuint source;
    Sound* currentSound;
    bool looping;
    bool isPositioned = false;

    static std::vector<AudioSource> pool;

public:
    /**
     * @brief Construct an audio source.
     * 
     * @param looping True if the source should loop (true by default).
     */
    AudioSource(bool looping = true);
    AudioSource(AudioSource &&other);
    ~AudioSource();

    /**
     * @brief Set the sound that this source should be playing.
     */
    void setSound(Sound &sound);

    /**
     * @brief Set the position of this audio source.
     */
    void setPosition(glm::vec3 pos);

    /**
     * @brief Set the velocity of this audio source.
     */
    void setVelocity(glm::vec3 vel);

    /**
     * @brief Set the pitch of this audio source.
     */
    void setPitch(float pitch);

    /**
     * @brief Set the gain for the audio source.
     */
    void setGain(float gain);

    /**
     * @brief Returns true if this source is playing right now.
     */
    bool isPlaying();

    /**
     * @brief Borrow an audio source from the pool.
     * 
     * The returned audio source is non-looping, and the reference is valid until the next
     * call to `borrowFromPool()`. If you call `setSound()` on this audio source, it will play
     * it right until the end. Only once the source stops playing, will `borrowFromPool()` return
     * the same source.
     */
    static AudioSource& borrowFromPool();
};

#endif