#include "Delay.hpp"

Delay::Delay(int iDelayInMs) {
  iType = DELAY;
  bStarted = false;
  this->iDelayInMs = iDelayInMs;
}

Delay::~Delay() {
  while (vChildren.size() > 0) {
    std::vector<Transition*>::iterator it = vChildren.begin();

    if (it != vChildren.end()) {
      delete *it;
      vChildren.erase(it);
    }
  }

  while (vToBeDeleted.size() > 0) {
    std::vector<AlterableObject*>::iterator it = vToBeDeleted.begin();

    if (it != vToBeDeleted.end()) {
      delete *it;
      vToBeDeleted.erase(it);
    }
  }
}

void Delay::Update() {
  if (!bStarted) {
    Start();
    oEndTime = oStartTime.addMSecs(iDelayInMs);
  }
}

bool Delay::Complete() {
  if ((bStarted) && (QTime::currentTime() > oEndTime)) {
    return true;
  }
  else {
    return false;
  }
}