#include <QCoreApplication>
#include <QLocale>
#include <QTranslator>
#include <QDebug>
#include <StoryTool.h>

using namespace Parse;
using namespace Parse::Result;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "DesParser_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

//    StoryChainDocumentParser frame(nullptr);
//    DocCore doc(nullptr, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storychain");
//    auto retlist = frame.analysis(&doc, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storychain");


//    StoryUnitDocumentParser frame(nullptr);
//    DocCore doc(nullptr, DocType::STORYUNIT, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyunit");
//    auto retlist = frame.analysis(&doc, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyunit");


//    StoryBoardDocumentParser frame(nullptr);
//    DocCore doc(nullptr, DocType::STORYBOARD, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyboard");
//    auto retlist = frame.analysis(&doc, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyboard");


    MakeTools::StoryTool tool;

//    auto path = "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyvolume";
    auto path = "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyunit";
    tool.compile(QFileInfo(path), "后台编译");

    auto doc = tool.getCore()->queryDocument(QFileInfo(path));
    auto retlist = doc->syntaxNodes();
    for (auto x : qAsConst(retlist)) {
        qDebug().noquote() << x->toString();
    }

    QList<ErrorMessage> errors;
    if(!tool.checkPass(errors))
        for(auto &x : errors)
            qDebug() << QString("%1, %2, %3, %4, %5").arg(x.Reason).arg(x.Text).arg(x.FilePath).arg(x.CodeRow).arg(x.CodeCol);

    return a.exec();
}
