#pragma once

#include <QDataStream>
#include <QObject>

namespace wima_planer_detail {

enum class STATE {
  NEEDS_INIT,
  WAITING_FOR_TILE_UPDATE,
  NEEDS_J_AREA_UPDATE,
  NEEDS_SURVEY_UPDATE,
  WAITING_FOR_SURVEY_UPDATE,
  NEEDS_PATH_UPDATE,
  UP_TO_DATE
};

QDebug &operator<<(QDebug &ds, STATE s);

enum class EVENT {
  INIT_DONE,
  M_AREA_NOT_READY,
  M_AREA_READY,
  M_AREA_PATH_CHANGED,
  S_AREA_PATH_CHANGED,
  CORRIDOR_PATH_CHANGED,
  M_AREA_TILES_CHANGED,
  M_AREA_PROGRESS_CHANGED,
  J_AREA_UPDATED,
  DEPOT_CHANGED,
  SURVEY_DESTROYED,
  MISSION_ITEMS_DESTROYED,
  SURVEY_UPDATE_TRIGGERED,
  SURVEY_UPDATED,
  PATH_CHANGED,
  PATH_UPDATED
};

QDebug &operator<<(QDebug &ds, EVENT s);

class StateMachine : public QObject {
  Q_OBJECT
public:
  explicit StateMachine(QObject *parent = nullptr);

  STATE state();
  void updateState(EVENT e);
  bool upToDate();
  bool surveyReady();

signals:
  void stateChanged();
  void upToDateChanged();
  void surveyReadyChanged();

private:
  void setState(STATE s);
  bool surveyReady(STATE s);
  bool upToDate(STATE s);

  STATE _state;
};

} // namespace wima_planer_detail
