#pragma once
#include "InBuildingMonitoringProcess.h"

class PerceptualState;

/**
 * @brief Process used to monitor the completion of units recruited inside buildings.
 */
class UnitTrainingMonitoringProcess : public InBuildingMonitoringProcessT<UnitTrainingMonitoringProcess>
{
public:
  UnitTrainingMonitoringProcess(const Process* parent, BWAPI::Unit* building, BWAPI::Unit* unit, const char* description);
  virtual void cancel();
  /////////
  // GUI //
  /////////
  virtual UnitRecordGroup _getUnitsInvolved() const
  {
    UnitRecordGroup unitsInvolved = InBuildingMonitoringProcessT::_getUnitsInvolved();
    unitsInvolved.insert(&m_unit, &m_unit + 1);
    return unitsInvolved;
  }
protected:
  friend class MonitoringProcessT<UnitTrainingMonitoringProcess>;
  friend class InBuildingMonitoringProcessT<UnitTrainingMonitoringProcess>;
  virtual void _output(std::ostream& out) const;
  virtual void onStart();
  virtual void onEnd();
  bool testCompletion();
  void setNewTimeout(bool error);
  void onUnitDestroyed(void*);

  BWAPI::Unit* const m_unit;
  const char* const m_description;
  Event<boost::tuples::tuple<>>::SubscriberID m_unitDestroyedSubscriberId;
  EVENT_HANDLER(UnitTrainingMonitoringProcess, onUnitDestroyed) m_unitDestroyedEventHandler;
};
