/***
   This file is part of libfly-ocr.

   Copyright (C) 2021 LLC "RusBITech-Astra" (https://astralinux.ru)

   libfly-ocr is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation, either version 3 of the
   License, or (at your option) any later version.

   Foobar is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with libfly-ocr.  If not, see <https://www.gnu.org/licenses/>.
***/

#ifndef OCRENGINE_H
#define OCRENGINE_H

#include <QObject>
#include <QImage>
#include <QList>
#include <QRectF>
#include "ocrenginefactory.h"
#include "fly-ocr_export.h"

class FLY_OCR_EXPORT OcrEngine : public QObject
{
    Q_OBJECT
public:
    explicit OcrEngine(QObject* parent = nullptr);
    virtual ~OcrEngine() {}
    virtual bool initialize(const QStringList& langs = QStringList(), bool analyseOnly = false) = 0;
    virtual void setPageSegmentationMode(int mode) = 0;
    virtual void setAutomaticPageSegmentation() = 0;
    virtual void setCharacterWhitelist(const QString& characters) = 0;
    virtual void setCharacterBlacklist(const QString& characters) = 0;
    virtual int pageCount() const = 0;
    virtual bool recognize(const QImage& image, int resolution, int page) = 0;
    virtual bool isRecognized(int page) = 0;
    virtual QByteArray getPageData(int page, OcrEngineFactory::Format format) const = 0;
    virtual void setPageData(int page, OcrEngineFactory::Format format, const QByteArray& data) = 0;
    virtual void cancel() = 0;
    virtual int progress() const = 0;
    virtual QList<QRectF> analyseLayout(const QImage& image, double* avgDeskew) = 0;
    virtual bool exportAs(OcrEngineFactory::Format format, const QString& path) = 0;
    virtual void removePage(int page) = 0;

    static void loadPlugins();
    static OcrEngine* create(QObject* parent = nullptr, const QList<FlyOcr::Lang>& langs = QList<FlyOcr::Lang>(), bool analyseOnly = false);
    static OcrEngine* create(QObject* parent = nullptr, const QStringList& langs = QStringList(), bool analyseOnly = false);
    static OcrEngineFactory* selected();
    static QList<FlyOcr::Lang> languages();
    static OcrEngineFactory::Formats supportedExportFormats();
    static OcrEngineFactory::Formats supportedPageDataFormats();
    static void select(const QString& shortName);
    static const QList<OcrEngineFactory*>& factories();
    static QString lookupLangCode(const QString& prefix);

private:
    static QList<OcrEngineFactory*>* m_factories;
    static QHash<QString, QString> m_langLookup;
};

#endif
