#pragma once

#include <QObject>
#include "WimaPolygon.h"
#include "QGCMapPolyline.h"
#include "QGCMapPolygon.h"
#include "WimaVehicleMeasurementPolygon.h"
#include "SettingsFact.h"

#include "QScopedPointer"

class WimaGlobalMeasurementPolygon : public WimaPolygon
{
    Q_OBJECT
public:
    WimaGlobalMeasurementPolygon(QObject* parent);
    WimaGlobalMeasurementPolygon(QGCMapPolygon* other, QObject* parent);

    Q_PROPERTY(Fact*                    bottomLayerAltitude         READ bottomLayerAltitude                                            CONSTANT)
    Q_PROPERTY(Fact*                    numberOfLayers              READ numberOfLayers                                                 CONSTANT)
    Q_PROPERTY(Fact*                    layerDistance               READ layerDistance                                                  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*      vehicleList                 READ vehicleList                                                    NOTIFY vehicleListChanged)
    Q_PROPERTY(QGCMapPolyline*          entryPolyline               READ entryPolyline                                                  NOTIFY entryPolylineChanged)

    Q_INVOKABLE void addVehicle(Vehicle *vehicle);
    Q_INVOKABLE void removeVehicle(int vehicleIndex);
    Q_INVOKABLE void recalculatesubPolygons();
    Q_INVOKABLE void removeAllVehicles();


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

    // Property accessors
    Fact*                                       bottomLayerAltitude     (void)       { return &_bottomLayerAltitude;}
    Fact*                                       numberOfLayers          (void)       { return &_numberOfLayers;}
    Fact*                                       layerDistance           (void)       { return &_layerDistance;}
    QmlObjectListModel*                         vehicleList             (void) const { return _vehicleList;}
    QGCMapPolyline*                             entryPolyline           (void) const { return _entryPolyline;}


    static const char* settingsGroup;
    static const char* bottomLayerAltitudeName;
    static const char* numberOfLayersName;
    static const char* layerDistanceName;


signals:
    void bottomLayerAltitudeChanged     (void);
    void numberOfLayersChanged          (void);
    void layerDistanceChanged           (void);
    void vehicleListChanged             (void);
    void entryPolylineChanged           (void);
    void subPolygonsChanged             (void);


private:
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact            _bottomLayerAltitude;
    SettingsFact            _numberOfLayers;
    SettingsFact            _layerDistance;


    QmlObjectListModel*     _vehicleList;
    QGCMapPolyline*         _entryPolyline;


};

