#pragma once

#include <QJsonObject>
#include <QObject>
#include <QString>

#include <functional>
#include <memory>

#include "geometry/snake.h"

#include "AreaData.h"

namespace routing {

class GeneratorBase : public QObject {
  Q_OBJECT
public:
  using Data = AreaData *;
  using Generator = std::function<bool(snake::Transects &)>;

  explicit GeneratorBase(QObject *parent = nullptr);
  explicit GeneratorBase(Data d, QObject *parent = nullptr);
  ~GeneratorBase();

  Q_PROPERTY(QString editorQml READ editorQml CONSTANT)
  Q_PROPERTY(QString mapVisualQml READ mapVisualQml CONSTANT)

  virtual QString editorQml() = 0;
  virtual QString mapVisualQml() = 0;

  virtual bool save(QJsonObject &obj) const = 0;
  virtual bool load(const QJsonObject &obj, QString &guiErrorMessage) = 0;

  virtual QString name() = 0;
  virtual QString abbreviation() = 0;

  virtual bool get(Generator &generator) = 0;

  Data data() const;
  void setData(Data d);

signals:
  void generatorChanged();
  void dataChanged();

protected:
  virtual void establishConnections();
  virtual void deleteConnections();
  Data _d;

private:
};

} // namespace routing
