#pragma once
#include "../../PerceptualState.h"
#include "MonitoringProcess.h"

/**
 * @brief Process used to monitor the completion of units that are not trained inside buildings
 *        (e.g. buildings themselves, archons morph, etc).
 */
class UnitCreationMonitoringProcess : public MonitoringProcessT<UnitCreationMonitoringProcess>
{
public:
  UnitCreationMonitoringProcess(const Process* parent, BWAPI::Unit* unit, const char* description);
  virtual void cancel();
  /////////
  // GUI //
  /////////
  virtual UnitRecordGroup _getUnitsInvolved() const
  {
    return UnitRecordGroup(&m_unit, &m_unit + 1);
  }
  static const TerminationMode UnitDestroyed;
protected:
  friend class MonitoringProcessT<UnitCreationMonitoringProcess>;
  virtual void _output(std::ostream& out) const;
  virtual void onStart();
  virtual void onEnd();
  void onTimeoutImpl();
  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(UnitCreationMonitoringProcess, onUnitDestroyed) m_unitDestroyedEventHandler;
};
