#include "WimaServiceArea.h"

const char* WimaServiceArea::wimaServiceAreaName = "Service Area";



WimaServiceArea::WimaServiceArea(QObject *parent)
    :   WimaArea (parent)
{
    init();
}

WimaServiceArea::WimaServiceArea(const WimaServiceArea &other, QObject *parent)
    :    WimaArea (other, parent)
{
    init();
}

/*!
 * \overload operator=()
 *
 * Calls the inherited operator WimaArea::operator=().
 */
WimaServiceArea &WimaServiceArea::operator=(const WimaServiceArea &other)
{
    WimaArea::operator=(other);

    return *this;
}

void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate)
{
    if(_takeOffPosition != coordinate){
        _takeOffPosition = coordinate;
        emit takeOffPositionChanged();
    }
}

void WimaServiceArea::setLandPosition(const QGeoCoordinate &coordinate)
{
    if(_landPosition != coordinate){
        _landPosition = coordinate;
        emit landPositionChanged();
    }
}

void WimaServiceArea::saveToJson(QJsonObject &json)
{
    this->WimaArea::saveToJson(json);
    json[areaTypeName] = wimaServiceAreaName;
}

bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString)
{
    if ( this->WimaArea::loadFromJson(json, errorString)) {
        bool retVal = true;
        // code for loading here
        return retVal;
    } else {
        qWarning() << errorString;
        return false;
    }
}

void print(const WimaServiceArea &area)
{
    QString message;
    print(area, message);
    qWarning() << message;
}

void print(const WimaServiceArea &area, QString &outputStr)
{
    print(static_cast<const WimaArea&>(area), outputStr);
    outputStr.append(QString("Takeoff Position: %s\n").arg(area._takeOffPosition.toString(QGeoCoordinate::Degrees)));
    outputStr.append(QString("Land Position: %s\n").arg(area._landPosition.toString(QGeoCoordinate::Degrees)));
}

void WimaServiceArea::init()
{
    this->setObjectName(wimaServiceAreaName);
}

