#ifndef PATCHLIST_H
#define PATCHLIST_H

#include <QObject>
#include <QTimer>
#include <QThread>
#include <QList>

#include "models/patch/patch.h"
#include "models/patch/textspatch.h"
#include "models/patch/graphicspatch.h"
#include "models/patch/soundspatch.h"
#include "models/patch/videospatch.h"

class PatchList : public QObject
{
    Q_OBJECT
public:
    explicit PatchList(LotroDatManager* mgr, QObject *parent = nullptr);

    ~PatchList();

    QList<Patch *> getPatchList();

    LotroDatManager* getManager();
signals:
    void progressChanged(Patch::OperationProgress total_status);
    void patchOperationsStarted();
    void patchOperationsFinished();
    void backupSettingsInfoChanged();

public slots:
    void startAutoUpdate();

    void stopAutoUpdate();

    void update();

    void initialize();

    void createBackup();

    void restoreFromBackup();

    void removeBackup();

    void forceInstallPatches();

    void cleanUpPatchDirectory();

private slots:
    void onPatchOperationStarted(Patch::Operation operation, Patch* patch);
    void onPatchOperationFinished(Patch::Operation operation, Patch* patch);
    void onPatchOperationProgressChanged(Patch::OperationProgress operation_progress, Patch* patch);

private slots:
    void onLotroManagerOperationFinished(QString operation_name, QVector<QVariant> args, bool result);
    void onLotroManagerOperationStarted(QString operation_name, QVector<QVariant> args);

private:
    LotroDatManager *lotro_mgr_ = nullptr;
    bool lotro_mgr_initialised_ = false;
    bool operations_running_ = false;

    TextsPatch *texts_patch_ = nullptr;
    GraphicsPatch *graphics_patch_ = nullptr;
    SoundsPatch *sounds_patch_ = nullptr;
    VideosPatch *videos_patch_ = nullptr;

    QThread *texts_patch_thread_;
    QThread *graphics_patch_thread_ = nullptr;
    QThread *sounds_patch_thread_ = nullptr;
    QThread *videos_patch_thread_ = nullptr;

    QMap<Patch*, Patch::OperationProgress> patch_operations_status_;

    quint32 active_operations_num_ = 0;
    bool auto_updates_enabled_ = false;

    QTimer patch_update_timer;    
};

#endif // PATCHLIST_H
