# pragma once

#include "TransectStyleComplexItem.h"

#include "PolygonCalculus.h"
#include "PlanimetryCalculus.h"
#include "GeoUtilities.h"
#include "QVector"
#include "Circle.h"
#include "SettingsFact.h"

class CircularSurveyComplexItem :public TransectStyleComplexItem
{
    Q_OBJECT
public:
    /// @param vehicle Vehicle which this is being contructed for
    /// @param flyView true: Created for use in the Fly View, false: Created for use in the Plan View
    /// @param kmlOrShpFile Polygon comes from this file, empty for default polygon
    CircularSurveyComplexItem(Vehicle* vehicle, bool flyView, const QString& kmlOrShpFile, QObject* parent);

    Q_PROPERTY(QGeoCoordinate refPoint READ refPoint WRITE setRefPoint NOTIFY refPointChanged)
    Q_PROPERTY(Fact* deltaR READ deltaR CONSTANT)
    Q_PROPERTY(Fact* deltaAlpha READ deltaAlpha CONSTANT)
    Q_PROPERTY(Fact* transectMinLength READ transectMinLength CONSTANT)
    Q_PROPERTY(bool autoGenerated READ autoGenerated NOTIFY autoGeneratedChanged)

    // Property setters
    void setRefPoint(const QGeoCoordinate &refPt);
    // Set this to true if survey was automatically generated, prevents initialisation from gui.
    void setAutoGenerated(bool autoGen);

    // Property getters
    QGeoCoordinate  refPoint()      const;
    Fact            *deltaR();
    Fact            *deltaAlpha();
    Fact            *transectMinLength();
    // Is true if survey was automatically generated, prevents initialisation from gui.
    bool            autoGenerated();

    // Overrides from ComplexMissionItem
    bool    load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    QString mapVisualQML        (void) const final { return QStringLiteral("SpericalSurveyMapVisual.qml"); }

    // Overrides from TransectStyleComplexItem
    void    save                (QJsonArray&  planItems) final;
    bool    specifiesCoordinate (void) const final { return true; }
    void    appendMissionItems  (QList<MissionItem*>& items, QObject* missionItemParent) final;
    void    applyNewAltitude    (double newAltitude) final;
    double  timeBetweenShots    (void) final;

    // Overrides from VisualMissionionItem
    QString commandDescription  (void) const final { return tr("Circular Survey"); }
    QString commandName         (void) const final { return tr("Circular Survey"); }
    QString abbreviation        (void) const final { return tr("C.S."); }
    bool    readyForSave        (void) const final;
    double  additionalTimeDelay (void) const final;

    static const char* settingsGroup;    
    static const char* deltaRName;
    static const char* deltaAlphaName;
    static const char* transectMinLengthName;

    static const char* jsonComplexItemTypeValue;
    static const char* jsonDeltaRKey;
    static const char* jsonDeltaAlphaKey;
    static const char* jsonTransectMinLengthKey;
    static const char* jsonReferencePointLongKey;
    static const char* jsonReferencePointLatKey;
    static const char* jsonReferencePointAltKey;

signals:
    void refPointChanged();
    void autoGeneratedChanged();

private slots:
    // Overrides from TransectStyleComplexItem
    void _rebuildTransectsPhase1    (void) final;
    void _recalcComplexDistance     (void) final;
    void _recalcCameraShots         (void) final;

signals:

private:
    void _appendLoadedMissionItems(QList<MissionItem*>& items, QObject* missionItemParent);
    void _buildAndAppendMissionItems(QList<MissionItem*>& items, QObject* missionItemParent);



    QGeoCoordinate _referencePoint; // center of the circular lanes, e.g. base station

    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact            _deltaR;
    SettingsFact            _deltaAlpha;
    SettingsFact            _transectMinLength;

    QTimer _updateTimer;

    bool _autoGenerated; // set to true if survey was automatically generated, prevents initialisation from gui
};



