#pragma once
#include "../../../../BWAPI_Addon.h"
#include "../../../../Utils/Component.h"
#include "../Behaviors/BehaviorState.h"
#include <BWAPI.h>

//Peut être forward declared si certaines fonctions sont envoyé dans un .h
#include "../../../../Utils/PersistentUnitGroup.h"

class ArbitratorUnitData;

/**
 * @brief Base class for low-level (BWAPI-level) actions.
 */
class Command : public Component, private boost::noncopyable
{
public:
  /**
   * @brief Constructs a new command associated with an existing behavior.
   * @param state The behavior state from which this command originates.
   */
  Command(BehaviorState& state)
    //: m_state(state)
  {
    unused(state);
  }

  virtual ~Command() {}

  /**
   * @brief Executes this command with a particular unit.
   * @param unit The unit which will execute the command.
   * @return Whether the unit successfully accomplished the command.
   */
  virtual bool execute(BWAPI::Unit* unit) const = 0;

  /**
   * @brief Executes this command with a particular group of units.
   * @param group The group of units which will execute the command.
   * @return Whether all units successfully accomplished the command.
   */
  bool executeForGroup(const PersistentUnitGroup* group) const
  {
    bool result = true;
    for (PersistentUnitGroup::const_iterator it = group->begin();
         it != group->end();
         ++it)
    {
      result = execute(*it) && result;
    }
    return result;
  }

  //
  // At the moment a command is considered terminated when the issuing behavior changes state.
  // This could be implemented differently, i.e. each command keeps a list of subscribers
  // and each behavior state is responsible for explicitely terminating its commands.
  //

  //typedef BehaviorState::OnStateExit OnActionEnded;
  //OnActionEnded& getActionEndedEvent() const { return m_state.getStateExitEvent(); }

protected:
  /**
   * @brief The state from which this command originates.
   */
  //BehaviorState& m_state;

private:
  Command& operator=(const Command&);
};
