#pragma once

#include <QObject>
#include "QGCMapPolygon.h"
#include "QmlObjectListModel.h"

#include "WimaPolygon.h"
#include "WimaGlobalMeasurementPolygon.h"
#include "WimaServicePolygon.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(QmlObjectListModel*      visualItems             READ visualItems                                                    NOTIFY visualItemsChanged)
    Q_PROPERTY(int                      currentPolygonIndex     READ currentPolygonIndex        WRITE setCurrentPolygonIndex        NOTIFY currentPolygonIndexChanged)


    // Property accessors
    PlanMasterController*       masterController       (void) const    { return _masterController;}
    MissionController*          missionController      (void) const    { return _missionController;}
    QmlObjectListModel*         visualItems            (void)          { return _visualItems; }
    int                         currentPolygonIndex    (void) const    { return _currentPolygonIndex; }




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

    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();

    Q_INVOKABLE void resetAllIsCurrentPolygon(void);



signals:
    void masterControllerChanged        (void);
    void missionControllerChanged       (void);
    void visualItemsChanged             (void);
    void currentPolygonIndexChanged     (int index);

private slots:
    void recalcVehicleCorridor();
    void recalcVehicleMeasurementAreas();
    void recalcAll();
    void recalcPolygonInteractivity(int index);


private:
    bool                        _planView;
    QmlObjectListModel*         _visualItems;
    PlanMasterController*       _masterController;
    MissionController*          _missionController;
    int                         _currentPolygonIndex;

};
