#ifndef __VIRTUAL_TIMER_VIRTUALTIMERDISTRIBUTOR_H__
#define __VIRTUAL_TIMER_VIRTUALTIMERDISTRIBUTOR_H__

#include <array>

#include "HwTimerInterface.h"
#include "VirtualTimerInterface.h"

namespace pinetime::virtual_timer
{
class VirtualTimerDistributor;
}
extern pinetime::virtual_timer::VirtualTimerDistributor virtual_timer_distributor;

namespace pinetime::virtual_timer
{

class VirtualTimerDistributor
{
    public:
        VirtualTimerDistributor(pinetime::interfaces::HwTimerInterface &);

        static inline VirtualTimerDistributor& instance() { return virtual_timer_distributor; }

        void register_timer(pinetime::interfaces::VirtualTimerInterface *);
        void unregister_timer(pinetime::interfaces::VirtualTimerInterface *);

        void notify(uint64_t);
        uint64_t tick();

    private:
        static const uint32_t MAX_TIMERS = 8;

        std::array<pinetime::interfaces::VirtualTimerInterface *, MAX_TIMERS> virtual_timer_list;
        pinetime::interfaces::HwTimerInterface & hw_timer;
        uint32_t num_registered_timers;
};

}

#endif
