#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() override;
  virtual QString mapVisualQml() override;

  virtual QString name() override;
  virtual QString abbreviation() override;

  virtual bool get(Generator &generator) override;

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

  void setReference(const QGeoCoordinate &reference);

  static const char *settingsGroup;
  static const char *distanceName;
  static const char *deltaAlphaName;
  static const char *minLengthName;
  static const char *refPointLongitudeName;
  static const char *refPointLatitudeName;
  static const char *refPointAltitudeName;

signals:
  void referenceChanged();

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

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

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

} // namespace routing
