#pragma once
#include "PatrolBaseBehavior.h"

/**
 * @brief Transition action returning the next checkpoint, returning to the first one when all checkpoints have
 *        been visited.
 */
class LoopNextCheckpoint : public TransitionAction
{
public:
  LoopNextCheckpoint(std::list<Position>::const_iterator& currentCheckpoint, const std::list<Position>& checkPoints)
    : m_currentCheckpoint(currentCheckpoint), m_checkPoints(checkPoints) {}
  void start()
  {
    if (++m_currentCheckpoint == m_checkPoints.end())
      m_currentCheckpoint = m_checkPoints.begin();
  }
protected:
  std::list<Position>::const_iterator& m_currentCheckpoint;
  const std::list<Position>& m_checkPoints;
};

/**
 * @brief The PatrolBehavior instructs a group to patrol along a sequence of checkpoints,
 *        returning to the first one when the loop is completed.
 */
class PatrolBehavior : public PatrolBaseBehavior<LoopNextCheckpoint>
{
public:
  PatrolBehavior(const Process* parent, unsigned int initialPriority, const PersistentUnitGroup* patrollingGroup, std::list<Position>& checkPoints)
    : PatrolBaseBehavior<NextCheckpoint>(initialPriority, patrollingGroup, checkPoints)
  {
  }
};