#pragma once


#include "QGCMapPolygon.h"
#include "QGCMapPolyline.h"
#include "Vehicle.h"
#include "qobject.h"
#include "WimaVehicle.h"





class WimaPolygon : public QObject //abstract base class for all WimaPolygons
{
    Q_OBJECT
public:
    WimaPolygon(QObject* parent = nullptr);
    WimaPolygon(QGCMapPolygon* other, QObject* parent = nullptr);



    Q_PROPERTY(double                   maxAltitude                 READ maxAltitude                WRITE setMaxAltitude                NOTIFY maxAltitudeChanged)
    Q_PROPERTY(QString                  mapVisualQML                READ mapVisualQML                                                   CONSTANT)
    Q_PROPERTY(QString                  editorQML                   READ editorQML                                                      CONSTANT)
    Q_PROPERTY(Vehicle*                 vehicle                     READ vehicle                    WRITE setVehicle                    NOTIFY vehicleChanged)
    Q_PROPERTY(QGCMapPolygon*           polygon                     READ polygon                                                        NOTIFY polygonChanged)
    Q_PROPERTY(QmlObjectListModel*      subPolygons                 READ subPolygons                                                    NOTIFY subPolygonsChanged)
    Q_PROPERTY(QmlObjectListModel*      subPolylines                READ subPolylines                                                   NOTIFY subPolylinesChanged)
    Q_PROPERTY(bool                     isCurrentPolygon            READ isCurrentPolygon           WRITE setIsCurrentPolygon           NOTIFY isCurrentPolygonChanged)

    //Property accessors
    double                  maxAltitude         (void) const    { return _maxAltitude;}
    Vehicle*                vehicle             (void) const    { return _vehicle.vehicle();}
    QGCMapPolygon*          polygon             (void) const    { return _polygon;}
    QmlObjectListModel*     subPolygons         (void) const    { return _subPolygons;}
    QmlObjectListModel*     subPolylines        (void) const    { return _subPolylines;}
    bool                    isCurrentPolygon    (void) const    { return _isCurrentPolygon;}

    virtual QString                     mapVisualQML    (void) const = 0;
    virtual QString                     editorQML       (void) const = 0;

    //Property setters
    void        setMaxAltitude     (double alt);
    void        setVehicle         (Vehicle* vehicle);
    void        setIsCurrentPolygon(bool isCurrentPolygon);


    QList<QGCMapPolygon*>* splitPolygonArea(int numberOfFractions); // use QScopedPointer to store return value


signals:
    void    maxAltitudeChanged      (void);
    void    vehicleChanged          (void);
    void    polygonChanged          (void);
    void    subPolygonsChanged      (void);
    void    subPolylinesChanged     (void);
    void    isCurrentPolygonChanged (void);


protected:
    double                  _maxAltitude;
    WimaVehicle             _vehicle;
    QGCMapPolygon*          _polygon;
    QmlObjectListModel*     _subPolygons;
    QmlObjectListModel*     _subPolylines;
    bool                    _isCurrentPolygon;
};


