#ifndef LOTROMANAGER_H
#define LOTROMANAGER_H

#include <QObject>
#include <QPushButton>

#include <queue>
#include <functional>

#include <LotroDat.h>

class LotroManager : public QObject
{
    Q_OBJECT
private:
    explicit LotroManager(QObject *parent = nullptr);

public:
    static LotroManager& getInstance() {
       static LotroManager lotro_mgr_instance;
       return lotro_mgr_instance;
    }

    bool execute(QStringList operation);

    bool isBusy();

private:

    void startGame();

    bool openDatFile(int id);

    void applyPatch(QString name);

    void applyGlobal();

    bool isDatReady();

    int checkDatFile();

    void applyMicroPatch();

    void applyLoadscreens();

    bool setGameLocale(QString locale);

    void changeBaseLocale(QString locale);

    void saveDatFiles();

    void processFile();

    void installMicroPatch();

    void prepareMicroPatch();

private:
    bool busy_;

    LOTRO_DAT::LOCALE dat_locale_;
    std::vector<LOTRO_DAT::DatFile> dat_files_;
    LOTRO_DAT::Database database_;

    std::deque<QStringList> operations_queue_;

    const std::vector<QString> available_operations_ = {
        "StartGame",
        "SetLocale",
        "ChangeBaseLocale",

        "ApplyGlobal",
        "ApplyPatch",
        "ApplyMicroPatch",
        "ApplyLoadScreens",

        "CheckDatFile",
        "SaveDatFiles"
    };

signals:
    void dat_operation_started(QString operation);
    void dat_operation_finished(QString operation, QString result = "");
    void update_hint_label(QString head, QString content);

private slots:
    void on_dat_operation_started(QString operation);
    void on_dat_operation_finished(QString operation, QString result = "");
};

#endif // LOTROMANAGER_H
