#include "GeneratorBase.h"

#include <QGeoCoordinate>

#include "SettingsFact.h"

class MeasurementArea;

namespace routing {

class CircularGenerator : public GeneratorBase {
  Q_OBJECT
public:
  CircularGenerator(QObject *parent = nullptr);
  CircularGenerator(Data d, QObject *parent = nullptr);

  Q_PROPERTY(QGeoCoordinate reference READ reference WRITE setReference NOTIFY
                 referenceChanged)
  Q_PROPERTY(Fact *distance READ distance CONSTANT)
  Q_PROPERTY(Fact *deltaAlpha READ deltaAlpha CONSTANT)
  Q_PROPERTY(Fact *minLength READ minLength CONSTANT)

  virtual QString editorQml() const override;
  virtual QString mapVisualQml() const override;

  virtual QString abbreviation() const override;
  virtual QString type() const override;

  virtual bool get(Generator &generator) override;

  QGeoCoordinate reference() const;
  Fact *distance();
  Fact *deltaAlpha();
  Fact *minLength();

  void setReference(const QGeoCoordinate &reference);

  //!
  //! \brief save Saves the generator.
  //! \param obj Json object for saveing.
  //! \return Returns true on success, false either.
  //!
  //! Saves distance, alpha and minLength.
  //! \note This methode does not save the data.
  //!
  virtual bool save(QJsonObject &obj) const override;
  virtual bool load(const QJsonObject &obj, QString &guiErrorMessage) override;

  static const char *settingsGroup;
  static const char *typeString;

signals:
  void referenceChanged();

public slots:
  Q_INVOKABLE void resetReferenceIfInvalid();
  Q_INVOKABLE void resetReference();

private slots:
  void onAreaListChanged();
  void onDataChanged();

private:
  void init();
  void setMeasurementArea(MeasurementArea *area);

  QGeoCoordinate _reference;
  QMap<QString, FactMetaData *> _metaDataMap;
  SettingsFact _distance;
  SettingsFact _deltaAlpha;
  SettingsFact _minLength;
  MeasurementArea *_measurementArea;
};
} // namespace routing
