#pragma once

#include <QObject>
#include "WimaArea.h"
#include "SettingsFact.h"
#include "WimaTrackerPolyline.h"
#include "WimaGOperationArea.h"

#include "QScopedPointer"

class WimaGOperationArea : public WimaArea
{
    Q_OBJECT
public:
    WimaGOperationArea(QObject* parent = nullptr);
    WimaGOperationArea(WimaArea* other, QObject* parent = nullptr);

    Q_PROPERTY(Fact*                    bottomLayerAltitude     READ bottomLayerAltitude    CONSTANT)
    Q_PROPERTY(Fact*                    numberOfLayers          READ numberOfLayers         CONSTANT)
    Q_PROPERTY(Fact*                    layerDistance           READ layerDistance          CONSTANT)
    Q_PROPERTY(Fact*                    borderPolygonOffset     READ borderPolygonOffset    CONSTANT)
    /*Q_PROPERTY(QmlObjectListModel*      vehicleList                 READ vehicleList                                                    NOTIFY vehicleListChanged)
    Q_PROPERTY(QmlObjectListModel*      vehiclePolygons             READ vehiclePolygons                                                NOTIFY vehiclePolygonsChanged)*/
    Q_PROPERTY(WimaTrackerPolyline*     polyline            READ polyline               CONSTANT)
    Q_PROPERTY(QGCMapPolygon*           borderPolygon       READ borderPolygon          NOTIFY      borderPolygonChanged)


    Q_INVOKABLE void addVehicle                 (WimaVehicle *vehicle);
    Q_INVOKABLE void removeVehicle              (int vehicleIndex);
                void setVehicleCorridor         (WimaVCorridor* corridor);
    /*Q_INVOKABLE void recalculatesubPolygons     ();
    Q_INVOKABLE void removeAllVehicles          ();
    Q_INVOKABLE void addVehiclePolygon          ();
    Q_INVOKABLE void removeVehiclePolygon       (int polygonIndex);
    Q_INVOKABLE void removeVehiclePolygon       (WimaVehicleMeasurementPolygon *wimaPolygon);*/


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

    // Property accessors
    Fact*                               bottomLayerAltitude     (void)       { return &_bottomLayerAltitude;}
    Fact*                               numberOfLayers          (void)       { return &_numberOfLayers;}
    Fact*                               layerDistance           (void)       { return &_layerDistance;}
    Fact*                               borderPolygonOffset   (void)       { return &_borderPolygonOffset;}
    /*QmlObjectListModel*                 vehicleList             (void) const { return _vehicleList;}
    QmlObjectListModel*                 vehiclePolygons         (void) const { return _vehiclePolygons;}*/
    WimaTrackerPolyline*                polyline                (void)       { return &_polyline;}
    WimaVCorridor*                      vehicleCorridor         (void)       { return _vehicleCorridor;}
    QGCMapPolygon*                      borderPolygon           (void)       { return &_borderPolygon;}


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


signals:
    void bottomLayerAltitudeChanged     (void);
    void numberOfLayersChanged          (void);
    void layerDistanceChanged           (void);
    //void vehicleListChanged             (void);
    void polylineChanged                (void);
    //void vehiclePolygonsChanged         (void);
    void vehicleCorridorChanged         (WimaVCorridor* corridor);
    void borderPolygonChanged           (void);

private slots:
    void recalcBorderPolygon            (void);


private:
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact            _bottomLayerAltitude;
    SettingsFact            _numberOfLayers;
    SettingsFact            _layerDistance;
    SettingsFact            _borderPolygonOffset;


    /*QmlObjectListModel*     _vehicleList;
    QmlObjectListModel*     _vehiclePolygons;*/
    WimaTrackerPolyline     _polyline;
    WimaVCorridor*          _vehicleCorridor;
    QGCMapPolygon           _borderPolygon;




};


