#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>;

enum class NemoStatus {
  NotConnected = 0,
  Connected = 1,
  Timeout = -1,
  InvalidHeartbeat = -2
};

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;
  int nemoStatus() 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);

  void enableRosBridge();
  void disableRosBride();

signals:
  void nemoProgressChanged();
  void nemoStatusChanged(int status);
  void calcInProgressChanged(bool inProgress);

protected:
  void run() override;

private:
  SnakeImplPtr pImpl;
};
