#pragma once

#include <QGeoCoordinate>
#include <QObject>

#include <memory>

#include "IDArray.h"
#include "LogicalArray.h"
#include "TileArray.h"
#include "TilePtrArray.h"
#include "geometry/ProgressArray.h"

// Singelton class used to interface measurement devices implementing the nemo
// interface.
class NemoInterface : public QObject {
  Q_OBJECT
  class Impl;
  using PImpl = std::unique_ptr<Impl>;

  NemoInterface();
  NemoInterface(NemoInterface &other) = delete;
  static NemoInterface *createInstance();

public:
  ~NemoInterface() override;
  static NemoInterface *instance();

  enum class STATUS {
    NOT_CONNECTED,
    READY,
    WEBSOCKET_DETECTED,
    TIMEOUT,
    INVALID_HEARTBEAT
  };
  Q_ENUM(STATUS)

  Q_PROPERTY(STATUS status READ status NOTIFY statusChanged)
  Q_PROPERTY(QString statusString READ statusString NOTIFY statusChanged)
  Q_PROPERTY(QString infoString READ infoString NOTIFY infoStringChanged)
  Q_PROPERTY(
      QString warningString READ warningString NOTIFY warningStringChanged)
  Q_PROPERTY(QString editorQml READ editorQml CONSTANT)
  Q_PROPERTY(bool running READ running NOTIFY runningChanged)

  QString editorQml();

  Q_INVOKABLE void start();
  Q_INVOKABLE void stop();

  // Tile editing.
  void addTiles(const TileArray &tileArray);
  void removeTiles(const IDArray &idArray);
  void clearTiles();
  TileArray getTiles(const IDArray &idArray);
  TileArray getAllTiles();
  LogicalArray containsTiles(const IDArray &idArray);
  std::size_t size();
  bool empty();

  // Progress.
  ProgressArray getProgress();
  ProgressArray getProgress(const IDArray &idArray);

  // Status.
  STATUS status() const;
  QString statusString() const;
  QString infoString() const;
  QString warningString() const;
  bool running();

signals:
  void statusChanged();
  void infoStringChanged();
  void warningStringChanged();
  void progressChanged(const ProgressArray &progressArray);
  void tilesChanged();
  void runningChanged();

private:
  PImpl pImpl;
};

#define pNemoInterface NemoInterface::instance()
