#ifndef WIMACONTROLLER_H
#define WIMACONTROLLER_H

#include <QObject>
#include "QGCMapPolygon.h"
#include "WimaPolygon.h"
#include "WimaGlobalMeasurementPolygon.h"
#include "WimaServicePolygon.h"
#include "WimaPolygonContainer.h"

#include "PlanMasterController.h"
#include "MissionController.h"


class WimaController : public QObject
{
    Q_OBJECT
public:
    WimaController(QObject *parent = nullptr);


    Q_PROPERTY(PlanMasterController*    masterController        READ masterController           WRITE setMasterController           NOTIFY masterControllerChanged)
    Q_PROPERTY(MissionController*       missionController       READ missionController          WRITE setMissionController          NOTIFY missionControllerChanged)
    Q_PROPERTY(QList<WimaPolygon*>&     visualItems             READ visualItems                                                    NOTIFY visualItemsChanged)
    Q_PROPERTY(QList<WimaPolygon*>&     editorItems             READ editorItems                                                    NOTIFY visualItemsChanged)

    // Property accessors
    PlanMasterController*       masterController       (void) const    { return _masterController;}
    MissionController*          missionController      (void) const    { return _missionController;}
    QList<WimaPolygon*>&        visualItems            (void)          { return _visualItemsContainer.returnFlatList(); }




    // Property setters
    void setMasterController        (PlanMasterController* masterController);
    void setMissionController       (MissionController* missionController);

    Q_INVOKABLE void addGlobalMeasurementArea();
    Q_INVOKABLE void removeArea(int index);
    Q_INVOKABLE void addServiceArea();

    Q_INVOKABLE void startMission();
    Q_INVOKABLE void abortMission();
    Q_INVOKABLE void pauseMission();
    Q_INVOKABLE void resumeMission();

    Q_INVOKABLE void saveMission();
    Q_INVOKABLE void loadMission();



signals:
    void masterControllerChanged        (void);
    void missionControllerChanged       (void);
    void visualItemsChanged             (void);

private slots:
    void recalcVehicleCorridor();
    void recalcVehicleMeasurementAreas();
    void recalcAll();


private:
    bool                        _planView;
    QList<WimaPolygon*>         _visualItems;
    PlanMasterController*       _masterController;
    MissionController*          _missionController;

};

#endif // WIMACONTROLLER_H
