#pragma once

#include "core/music.h"

#include <SFML/Audio/Music.hpp>
#include <SFML/System/Clock.hpp>

class MusicSFML : public kku::Music
{
public:
    explicit MusicSFML();
    virtual bool open(const std::string& filepath) override;

    virtual void play() override;
    virtual void pause() override;
    virtual void stop() override;

    virtual bool isPlaying() const override;

    virtual void setVolume(float volume) override;

    virtual void setOffset(const kku::microsec& offset) override;
    virtual void moveOffset(const kku::microsec& delta) override;

    virtual kku::microsec fetchOffset() override;
    virtual kku::microsec getDuration() const override;

private:
    sf::Music _music;
    sf::Clock _offset_interpolator;

    kku::microsec _sfml_music_offset;
    kku::microsec _previous_frame_offset;
    kku::microsec _absolute_offset;
};
