#pragma once

#include "QScopedPointer"
#include <QObject>

#include "WimaArea.h"

#include "SettingsFact.h"


class WimaMeasurementArea : public WimaArea
{
    Q_OBJECT
public:
    WimaMeasurementArea(QObject* parent = nullptr);
    WimaMeasurementArea(const WimaMeasurementArea &other, QObject *parent = nullptr);
    WimaMeasurementArea &operator=(const WimaMeasurementArea &other);

    Q_PROPERTY(Fact*                bottomLayerAltitude     READ bottomLayerAltitudeFact    CONSTANT)
    Q_PROPERTY(Fact*                numberOfLayers          READ numberOfLayersFact         CONSTANT)
    Q_PROPERTY(Fact*                layerDistance           READ layerDistanceFact          CONSTANT)

    // Overrides from WimaPolygon
    QString         mapVisualQML    (void) const { return "WimaMeasurementAreaMapVisual.qml";}
    QString         editorQML       (void) const { return "WimaMeasurementAreaEditor.qml";}

    // Property accessors
    Fact*           bottomLayerAltitudeFact (void)          { return &_bottomLayerAltitude;}
    Fact*           numberOfLayersFact      (void)          { return &_numberOfLayers;}
    Fact*           layerDistanceFact       (void)          { return &_layerDistance;}
    double          bottomLayerAltitude     (void) const    { return _bottomLayerAltitude.rawValue().toDouble();}
    int             numberOfLayers          (void) const    { return _numberOfLayers.rawValue().toInt();}
    double          layerDistance           (void) const    { return _layerDistance.rawValue().toDouble();}

    // Member Methodes
    void saveToJson(QJsonObject& json);
    bool loadFromJson(const QJsonObject& json, QString &errorString);

    // Friends
    friend void print(const WimaMeasurementArea& area, QString outputStr);
    friend void print(const WimaMeasurementArea& area);

    // Static Variables
    static const char* settingsGroup;
    static const char* bottomLayerAltitudeName;
    static const char* numberOfLayersName;
    static const char* layerDistanceName;
    static const char* WimaMeasurementAreaName;

signals:
    void bottomLayerAltitudeChanged     (void);
    void numberOfLayersChanged          (void);
    void layerDistanceChanged           (void);

public slots:
    void setBottomLayerAltitude (double altitude);
    void setNumberOfLayers      (double numLayers);
    void setLayerDistance       (double layerDistance);

private:
    // Member Methodes
    void init();

    // Members
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact            _bottomLayerAltitude;
    SettingsFact            _numberOfLayers;
    SettingsFact            _layerDistance;
};


