#include "tasksAmmFim.h"
#include <QDomDocument>
#include <QFile>


int TaskAmmFim::lastID = 1;

void TaskAmmFim::initialize(int id, QString type, QString title, QString status, QString created_date, QString changed_date)
{
    this->id = id;
    this->type = type;
    this->title = title;
    this->status = status;
    this->created_date = created_date;
    this->changed_date = changed_date;
}

void TaskAmmFim::addMalfunction(Malfunction malfunction)
{
    malfunctionList.append(malfunction);
}

void Malfunction::initialize(QString dmCode, QString num, QString description)
{
    this->dmCode = dmCode;
    this->num = num;
    this->description = description;
}

void Malfunction::addMalfunctionSign(MalfunctionSign sign)
{
    malfunctionSigns.append(sign);
}

void MalfunctionSign::initialize(int type, QString description)
{
    this->type = type;
    this->description = description;
}


QString SubProc::getDmCode() const
{
    return dmCode;
}

QString SubProc::getTitle() const
{
    return title;
}

void SubProc::setDmCode(const QString &value)
{
    dmCode = value;
}

void SubProc::setTitle(const QString &value)
{
    title = value;
}

QString SubProc::getModeListStr() const
{
    return modeListStr;
}

ModeList SubProc::getModeList() const
{
    return modeList;
}

void SubProc::setModeList(const ModeList &value)
{
    this->modeList = value;
    this->modeListStr = buildCanplay(value);
}

void SubProc::setModeListStr(const QString &value)
{
    this->modeListStr = value;
    this->modeList = parseCanplay(value);
}

QString SubProc::buildCanplay(ModeList modeList)
{
    QString canplay = QString("%1/%2/%3/%4").arg(modeList.demo?"+":"-", modeList.train?"+":"-", modeList.exam?"+":"-", modeList.autoM?"+":"-");
    return canplay;
}

ModeList SubProc::parseCanplay(QString canplay)
{
    ModeList modeList;

    if(canplay == "")
    {
        modeList.demo = false;
        modeList.train = false;
        modeList.exam = false;
        modeList.autoM = false;
    }
    else
    {
        QStringList list = canplay.split("/");

        if(list.at(0) == "+")
            modeList.demo = true;
        else
            modeList.demo = false;

        if(list.at(1) == "+")
            modeList.train = true;
        else
            modeList.train = false;

        if(list.at(2) == "+")
            modeList.exam = true;
        else
            modeList.exam = false;

        if(list.at(3) == "+")
            modeList.autoM = true;
        else
            modeList.autoM = false;
    }

    return modeList;
}
