#include <memory>
#include <functional>

class Animation;

class Animator {
private:
    bool paused;
    float timeElapsed;
    unsigned int currentFrameIndex;
    std::shared_ptr<Animation> animation;

    void play(float delta);
    void handleEndOfAnimation();
    float getCurrentFrameDuration() const;

protected:
    float getTimeElapsed() const;
    unsigned int getCurrentFrameIndex() const;
    std::shared_ptr<Animation> getAnimation() const;

public:
    Animator();
    virtual ~Animator();

    /**
     * Starts playback from the beginning.
     */
    void rewind();

    /**
     * Pauses any currently playing animation. Calls to Animator::update will
     * still work but playback will not advance.
     *
     * @see Animator::isPaused
     * @see Animator::unpause
     */
    void pause();


    const bool isPaused() const;

    /**
     * Resumes animation playback.
     *
     * @see Animator::pause
     * @see Animator::isPaused
     */
    void unpause();

    /**
     * Updates animation playback by a specified amount of time.
     * 
     * @param delta time to advance playback, in seconds
     */
    virtual void update(float delta);

    /**
     * Sets the animation to play.
     */
    void setAnimation(std::shared_ptr<Animation> animation);
};
