#include "internallogicmanager.h"
#include "widgets/mainwindow.h"


InternalLogicManager::InternalLogicManager(MainWindow *gui_, QSettings *settings_, QObject *parent)
{
    qDebug() << "Creating patch downloader instance & thread";
    patch_downloader_thread = new QThread();
    patch_downloader = new PatchDownloader(settings);

    lotro_manager_thread = new QThread();
    lotro_manager = new LotroDatManager(settings);

    connect(patch_downloader, &PatchDownloader::checkForUpdatesStarted, this, &InternalLogicManager::semiCriticalSectionEntered, Qt::BlockingQueuedConnection);
    connect(patch_downloader, &PatchDownloader::checkForUpdatesFinished, this, &InternalLogicManager::semiCriticalSectionLeaved, Qt::BlockingQueuedConnection);
    connect(lotro_manager, &LotroDatManager::processStarted, this, &InternalLogicManager::criticalSectionEntered, Qt::BlockingQueuedConnection);
    connect(lotro_manager, &LotroDatManager::processFinished, this, &InternalLogicManager::criticalSectionLeaved, Qt::BlockingQueuedConnection);
//    connect(lotro_manager, &LotroDatManager::caughtError, this, &MainWindow::onLotroManagerErrorOccured, Qt::BlockingQueuedConnection);

    connect(lotro_manager_thread, &QThread::finished, lotro_manager, &QObject::deleteLater, Qt::QueuedConnection);
    connect(patch_downloader_thread, &QThread::finished, patch_downloader, &QObject::deleteLater, Qt::QueuedConnection);

    patch_downloader->moveToThread(patch_downloader_thread);
    lotro_manager->moveToThread(lotro_manager_thread);
    lotro_manager_thread->start();
    patch_downloader_thread->start();
}

InternalLogicManager::~InternalLogicManager()
{
}

void InternalLogicManager::startInitPipeline()
{

}

void InternalLogicManager::startGame(QString locale)
{

}

void InternalLogicManager::lotroSettingsUpdated()
{

}

void InternalLogicManager::createLotroFilesBackup()
{

}

void InternalLogicManager::removeLotroFilesBackup()
{

}

void InternalLogicManager::applySelectedPatches()
{

}

void InternalLogicManager::updateSettingsChanged()
{

}

void InternalLogicManager::terminateThreads()
{

}

void InternalLogicManager::stopThreads()
{
    lotro_manager_thread->quit();
    patch_downloader_thread->quit();

    lotro_manager_thread->wait();
    patch_downloader_thread->wait();
}

void InternalLogicManager::checkFirstTimeOpening()
{

}

void InternalLogicManager::checkGameFolderCorrectness()
{

}

void InternalLogicManager::checkDatFilesExist()
{

}

void InternalLogicManager::processLotroManagerInit()
{

}

void InternalLogicManager::processPatchDownloaderInit()
{

}

void InternalLogicManager::checkBackupExist()
{

}

void InternalLogicManager::checkUserHasEnteredPatchOptions()
{

}

void InternalLogicManager::checkDatFileWasPatched()
{

}
