#include "WimaMeasurementAreaData.h"
#include "SnakeTile.h"

const char *WimaMeasurementAreaData::typeString = "WimaMeasurementAreaData";

WimaMeasurementAreaData::WimaMeasurementAreaData(QObject *parent)
    : WimaAreaData(parent) {}

WimaMeasurementAreaData::WimaMeasurementAreaData(
    const WimaMeasurementAreaData &other, QObject *parent)
    : WimaAreaData(parent) {
  *this = other;
}

WimaMeasurementAreaData::WimaMeasurementAreaData(
    const WimaMeasurementArea &other, QObject *parent)
    : WimaAreaData(parent) {
  *this = other;
}

bool WimaMeasurementAreaData::
operator==(const WimaMeasurementAreaData &other) const {
  return this->WimaAreaData::operator==(other) &&
         this->_tileData == other.tileData() &&
         this->center() == other.center();
}

bool WimaMeasurementAreaData::
operator!=(const WimaMeasurementAreaData &other) const {
  return !(*this == other);
}

void WimaMeasurementAreaData::setTileData(const TileData &d) {
  if (this->_tileData != d) {
    this->_tileData = d;
    emit tileDataChanged();
  }
}

void WimaMeasurementAreaData::setProgress(const QVector<int> &d) {
  if (this->_progress != d && d.size() == this->_tileData.tiles.count()) {
    this->_progress = d;
    emit progressChanged();
  }
}

/*!
 * \overload operator=();
 *
 * Assigns \a other to the invoking object.
 */
WimaMeasurementAreaData &WimaMeasurementAreaData::
operator=(const WimaMeasurementAreaData &other) {
  assign(other);

  return *this;
}

/*!
 * \overload operator=();
 *
 * Assigns \a other to the invoking object.
 */
WimaMeasurementAreaData &WimaMeasurementAreaData::
operator=(const WimaMeasurementArea &other) {
  assign(other);

  return *this;
}

QString WimaMeasurementAreaData::mapVisualQML() const {
  return QStringLiteral("WimaMeasurementAreaDataVisual.qml");
}

QString WimaMeasurementAreaData::type() const { return this->typeString; }

QmlObjectListModel *WimaMeasurementAreaData::tiles() {
  return &this->_tileData.tiles;
}

const QmlObjectListModel *WimaMeasurementAreaData::tiles() const {
  return &this->_tileData.tiles;
}

const QVariantList &WimaMeasurementAreaData::tileCenterPoints() const {
  return this->_tileData.tileCenterPoints;
}

QVariantList &WimaMeasurementAreaData::tileCenterPoints() {
  return this->_tileData.tileCenterPoints;
}

const TileData &WimaMeasurementAreaData::tileData() const {
  return this->_tileData;
}

TileData &WimaMeasurementAreaData::tileData() { return this->_tileData; }

const QVector<int> &WimaMeasurementAreaData::progress() const {
  return this->_progress;
}

QVector<int> &WimaMeasurementAreaData::progress() { return this->_progress; }

void WimaMeasurementAreaData::assign(const WimaMeasurementAreaData &other) {
  WimaAreaData::assign(other);
  setTileData(other._tileData);
  setProgress(other._progress);
}

void WimaMeasurementAreaData::assign(const WimaMeasurementArea &other) {
  WimaAreaData::assign(other);
  if (other.ready()) {
    setTileData(other.tileData());
    setProgress(other.progress());
  } else {
    qWarning()
        << "WimaMeasurementAreaData::assign(): WimaMeasurementArea not ready.";
  }
}

bool operator==(const WimaMeasurementAreaData &m1,
                const WimaMeasurementArea &m2) {
  return operator==(*static_cast<const WimaAreaData *>(&m1),
                    *static_cast<const WimaArea *>(&m2)) &&
         m1.tileData() == m2.tileData() && m1.progress() == m2.progress();
}

bool operator!=(const WimaMeasurementAreaData &m1,
                const WimaMeasurementArea &m2) {
  return !(m1 == m2);
}

bool operator==(const WimaMeasurementArea &m1,
                const WimaMeasurementAreaData &m2) {
  return m2 == m1;
}

bool operator!=(const WimaMeasurementArea &m1,
                const WimaMeasurementAreaData &m2) {
  return m2 != m1;
}
