#ifndef TASKTREEPREPARATION_H
#define TASKTREEPREPARATION_H

#include <QObject>
#include <QTreeWidgetItem>
#include <QDomElement>
#include <QMutex>
#include "module.h"
#include "tasksAmmFim.h"

enum ColumnsTreeAMM{
    clmnAMM_PMorDM = 0,
    clmnAMM_code,
    clmnAMM_ID,
    clmnAMM_status,
    clmnAMM_count
};

enum ColumnsTreeFIM{
    clmnFIM_Title = 0,
    clmnFIM_ID,
    clmnFIM_status,
    clmnFIM_count
};

enum TypeListTreeAMMFIM
{
    listCommon = 0,
    listForTrainee,
    listOneTask
};


class TaskAMMFIMTreePreparation : public QObject
{
    Q_OBJECT
public:
    explicit TaskAMMFIMTreePreparation(TypeListTreeAMMFIM type, QObject *parent = nullptr);
    ~TaskAMMFIMTreePreparation();

public:
    TaskAmmFim getTaskFIMbyID(int id);
    TaskAmmFim getTaskAMMbyID(int id);

    ModuleType getTypeModuleAMMbyID(int id);

private:
    QTreeWidgetItem* addModuleToTreeWidgetAMM(Module* module, bool flOnlyActive = false, QTreeWidgetItem* parentItem = nullptr);

    void loadAMMtasksFromXML(QByteArray array);
    void domElementParserAMM(QDomElement element, Module* moduleParent);
    void deleteAllModulsAMM();

    void loadFIMtasksFromXML(QByteArray array);

public Q_SLOTS:
    void slot_prepareAMMListItems(QByteArray array, bool flOnlyActive, bool flRequestFirst);
    void slot_prepareAMMListItemsForTrainee(QList<TaskAmmFim> listTasks);

    void slot_prepareFIMListItems(QByteArray array);
    void slot_prepareFIMListItemsForTrainee(QList<TaskAmmFim> listTasks);

    void slot_stopParserPreparation();

Q_SIGNALS:
    void signal_listAMMItemsReady(QList<QTreeWidgetItem*> listItemsAMM);
    void signal_listFIMItemsReady(QList<QTreeWidgetItem*> listItemsFIM);

private:
    QList<QTreeWidgetItem*> listItemsAll;
    QList<QTreeWidgetItem*> listItemsOnlyActive;

    QList<Module*> listAllModulesAMM;

    QList<TaskAmmFim> listTasksFIM;
    QList<TaskAmmFim> listTasksAMM;

    bool flagStop;
    TypeListTreeAMMFIM type;

    QMutex mtxAccess;

    int countItems = 0;
};

#endif // TASKTREEPREPARATION_H
