#pragma once
#include "../Behavior.h"
#include "../../../../../Scheduler/SchedulerTaskHelper.h"

/**
 * @brief Utility class for a state which executes a timer. Inheritors must supply a onTimer() method. 
 * onTimer() will be called every refreshDelay frame(s).
 */
template<class DerivedBehavior, class DerivedState>
class TimerState : public BehaviorStateT<DerivedBehavior, DerivedState>
{
public:
  TimerState(DerivedBehavior& behavior, size_t refreshDelay, size_t waitingTimeBeforeExecution)
    : BehaviorStateT(behavior)
    , m_timerEvent(*static_cast<DerivedState *>(this), Scheduler::FSM_SCHEDULING_PRIORITY, refreshDelay, waitingTimeBeforeExecution)
  {}
  void onEnter()
  {
  }
  void onExit() 
  {
  }

  void onTimerT() 
  {
    static_cast<DerivedState *>(this)->onTimer();
  }

  typedef SCHEDULER_EVENT_HANDLER(DerivedState, onTimerT) TimerEvent;

protected:

  // Transitions
  TimerEvent m_timerEvent;
};