#ifndef GAMERES_H
#define GAMERES_H

#include <QObject>
#include <QThread>
#include <LotroDat.h>
using namespace LOTRO_DAT;

class GameRes : public QObject {
Q_OBJECT

    // Singleton realisation of class
private:
    GameRes();
    GameRes(const GameRes&);
    GameRes& operator=(GameRes&);

public:
    GameRes* getInstance() {
        static GameRes instance;
        return instance;
    }

    // Basic public functions
public:
    void openDatFile(int id);               // Opens .dat file by its id (0-local_English.dat)

    void closeDatFile(int id);              // Closes .dat file by its id

    void applyPatch(QString name);          // Applies patch by its name (sounds/texts/images/videos/textures/loadscreens)

    void setGameLocale(QString locale);     // Sets locale by its name (Original/RU)

    void startGame();                       // Starts detatched game application process

    void installMicroPatch();               // Installs latest micro-patch

    void applyAll();                        // Installs all patches (applyGlobal)

    bool isBusy() {}                        // !!!!TO BE DONE Returns true if operations with game res are working now

    void checkDatFile();                    // Checks and returns information if dat file is clear/updated

signals:
    // Signals for every public function finish. Gives result int value.
    void openDatFileFinished(int result);
    void closeDatFileFinished(int result);
    void applyPatchFinished(int result);
    void setGameLocaleFinished(int result);
    void startGameFinished(int result);
    void installMicroPatchFinished(int result);
    void applyAllFinished(int result);
    void checkDatFileFinished(int result);

    // Signals for gui updating - describe process of patching.
    void startedPatching(QString patchname);
    void updatedPatchPercent(int percent);
    void finishedPatching(QString patchname, QString result);

private:
    void processFile();
    void prepareMicroPatch();
    void applyMicroPatch();
    void applyLoadscreens();
    void saveLocale(int locale, QPushButton *button);
    bool isDatReady(); // Checks if file is ready to write data

private:
    QThread *thread_;
    bool busy_;
    DatFile datfiles_[5];
    Database db_;
    LOCALE locale_;
};

#endif // GAMERES_H
