#include "GeneratorBase.h"

namespace routing {

GeneratorBase::GeneratorBase(QObject *parent)
    : GeneratorBase(nullptr, parent) {}

GeneratorBase::GeneratorBase(GeneratorBase::Data d, QObject *parent)
    : QObject(parent), _d(d) {
  establishConnections();
  connect(_d, &AreaData::areaListChanged, this,
          &GeneratorBase::_areaListChangedHandler);
}

GeneratorBase::~GeneratorBase() {}

GeneratorBase::Data GeneratorBase::data() const { return _d; }

void GeneratorBase::setData(Data d) {
  if (d != nullptr) {
    if (_d != nullptr) {
      disconnect(_d, &AreaData::areaListChanged, this,
                 &GeneratorBase::_areaListChangedHandler);
    }
    deleteConnections();
    _d = d;
    establishConnections();
    connect(_d, &AreaData::areaListChanged, this,
            &GeneratorBase::_areaListChangedHandler);
  }
}

void GeneratorBase::establishConnections() {}

void GeneratorBase::deleteConnections() {}

void GeneratorBase::_areaListChangedHandler() {
  deleteConnections();
  establishConnections();
  emit generatorChanged();
}

} // namespace routing
