#include "extractors/office-extractor.h"
#include "mime-utils.h"
#include "simple-extraction-result.h"

#include <QCoreApplication>
#include <QFileInfo>
#include <QMimeDatabase>

#include <cstdio>

using namespace UkuiFileMetadata;

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    if (argc != 2) {
        std::fprintf(stderr, "usage: %s <file>\n", argv[0]);
        return 2;
    }

    const QString fileName = QFileInfo(QString::fromLocal8Bit(argv[1])).absoluteFilePath();
    QMimeDatabase mimeDb;
    const QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name();

    OfficeExtractor plugin;
    SimpleExtractionResult result(fileName, mimeType,
                                  ExtractionResult::ExtractPlainText | ExtractionResult::ExtractMetaData);
    plugin.extract(&result);

    std::printf("mime=%s\ntext_len=%d\n",
                mimeType.toLocal8Bit().constData(),
                result.text().size());
    return 0;
}
