#pragma once

#include <QGeoCoordinate>
#include <QList>
#include <QObject>
#include <QThread>

#include "QNemoHeartbeat.h"
#include "QNemoProgress.h"
#include "SnakeTiles.h"

#include <boost/units/systems/si.hpp>

using namespace boost::units;
using Length = quantity<si::length>;
using Area = quantity<si::area>;

class SnakeDataManager : public QThread {
  Q_OBJECT

  class SnakeImpl;
  using SnakeImplPtr = std::unique_ptr<SnakeImpl>;

public:
  SnakeDataManager(QObject *parent = nullptr);
  ~SnakeDataManager() override;

  void setMeasurementArea(const QList<QGeoCoordinate> &measurementArea);
  void setServiceArea(const QList<QGeoCoordinate> &serviceArea);
  void setCorridor(const QList<QGeoCoordinate> &corridor);

  const QmlObjectListModel *tiles() const;
  QVariantList tileCenterPoints() const;
  QNemoProgress nemoProgress() const;
  bool calcInProgress() const;
  QString errorMessage() const;
  bool success() const;

  QVector<QGeoCoordinate> waypoints() const;
  QVector<QGeoCoordinate> arrivalPath() const;
  QVector<QGeoCoordinate> returnPath() const;

  Length lineDistance() const;
  void setLineDistance(Length lineDistance);

  Length minTransectLength() const;
  void setMinTransectLength(Length minTransectLength);

  Area minTileArea() const;
  void setMinTileArea(Area minTileArea);

  Length tileHeight() const;
  void setTileHeight(Length tileHeight);

  Length tileWidth() const;
  void setTileWidth(Length tileWidth);

signals:
  void calcInProgressChanged(bool inProgress);

protected:
  void run() override;

private:
  SnakeImplPtr pImpl;
};
