#include "WimaPlanData.h"

WimaPlanData::WimaPlanData(QObject *parent)
    :   QObject (parent)
{

}

WimaPlanData::WimaPlanData(const WimaPlanData &other, QObject *parent)
    :   QObject (parent)
{
    *this = other;
}

/*!
 * \fn WimaPlanData &WimaPlanData::operator=(const WimaPlanData &other)
 *
 * Copies the data area list of \a other to the calling \c WimaPlanData object.
 * Returns a reference to the calling \c WimaPlanData object.
 */
WimaPlanData &WimaPlanData::operator=(const WimaPlanData &other)
{
    // copy wima areas
    QList<const WimaAreaData*> areaList = other.areaList();
    _areaList.clear();
    for (int i = 0; i < areaList.size(); i++) {
        const WimaAreaData *areaData = areaList[i];
        // determine area type and append
        if       (areaData->type() == WimaJoinedAreaData::typeString) {
            this->append(*qobject_cast<const WimaJoinedAreaData*>(areaData));
        }else if (areaData->type() == WimaServiceAreaData::typeString) {
            this->append(*qobject_cast<const WimaServiceAreaData*>(areaData));
        }else if (areaData->type() == WimaMeasurementAreaData::typeString) {
            this->append(*qobject_cast<const WimaMeasurementAreaData*>(areaData));
        }else if (areaData->type() == WimaCorridorData::typeString) {
            this->append(*qobject_cast<const WimaCorridorData*>(areaData));
        }
    }

    // copy mission items
    _missionItems = other.missionItems();

    return *this;
}


/*!
 * \fn void WimaPlanData::append(const WimaAreaData &areaData)
 *
 * Adds a WimaAreaData item.
 */
void WimaPlanData::append(const WimaJoinedAreaData &areaData)
{
    _joinedArea = areaData;

    if( !_areaList.contains(&_joinedArea) ) {
        _areaList.append(&_joinedArea);
    }
}

/*!
 * \fn void WimaPlanData::append(const WimaServiceAreaData &areaData)
 *
 * Adds a WimaServiceAreaData item.
 */
void WimaPlanData::append(const WimaServiceAreaData &areaData)
{
    _serviceArea = areaData;

    if( !_areaList.contains(&_serviceArea) ) {
        _areaList.append(&_serviceArea);
    }
}

/*!
 * \fn void WimaPlanData::append(const WimaServiceAreaData &areaData)
 *
 * Adds a WimaCorridorData item.
 */
void WimaPlanData::append(const WimaCorridorData &areaData)
{
    _corridor = areaData;

    if( !_areaList.contains(&_corridor) ) {
        _areaList.append(&_corridor);
    }
}

/*!
 * \fn void WimaPlanData::append(const WimaServiceAreaData &areaData)
 *
 * Adds a WimaMeasurementAreaData item.
 */
void WimaPlanData::append(const WimaMeasurementAreaData &areaData)
{
    _measurementArea = areaData;

    if( !_areaList.contains(&_measurementArea) ) {
        _areaList.append(&_measurementArea);
    }
}

void WimaPlanData::append(const QList<MissionItem *> &missionItems)
{
    for (MissionItem *item : missionItems) {
        MissionItem copy = MissionItem(*item, this);
        _missionItems.append(copy);
    }
}

/*!
 * \fn void WimaPlanData::append(const WimaServiceAreaData &areaData)
 *
 * Clears all stored objects
 */
void WimaPlanData::clear()
{
    _areaList.clear();
    _missionItems.clear();
}

QList<const WimaAreaData *> WimaPlanData::areaList() const
{
    return _areaList;
}

QList<MissionItem> WimaPlanData::missionItems() const
{
    return _missionItems;
}

/*!
 * \class WimaPlanData
 * \brief Class storing data generated by the \c WimaPlaner class.
 *
 * This class is designed to store data generated by the \c WimaPlaner class and
 * meant for data exchange between the \c WimaController and the \c WimaPlanner.
 * It stores a QList of \c WimaAreaData objects, called area data list, containing the data of serveral \c WimaAreas
 * generated by the \c WimaPlaner.
 *
 * \sa QList
 */
