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

   Copyright (C) 2016-2020 Sandro Mani <manisandro@gmail.com>
   Copyright (C) 2021 LLC "RusBITech-Astra" (https://astralinux.ru)

    Based on gImageReader source code by Sandro Mani under the GNU
    General Public License (GPL) version 3 or later

   Foobar is free software: you can redistribute it and/or modify
   it under the terms of the GNU 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 General Public License
   along with fly-ocr. If not, see <https://www.gnu.org/licenses/>.
***/

#ifndef OUTPUTEDITOR_H
#define OUTPUTEDITOR_H

#include <QObject>
#include <QPointer>
#include <fly-ocr/ocrengine.h>
#include "configdialog.h"
#include "sourcedocumentmodel.h"

class OcrEngine;

class OutputEditor : public QWidget
{
    Q_OBJECT
public:
    struct PageInfo {
        QString filename;
        int page;
        double angle;
        int resolution;
    };
    struct ReadSessionData {
        virtual ~ReadSessionData() = default;
        bool prependFile;
        bool prependPage;
        PageInfo pageInfo;
    };
    class BatchProcessor
    {
    public:
        virtual ~BatchProcessor() = default;
        virtual QString fileSuffix() const = 0;
        virtual void writeHeader(QIODevice* /*dev*/, const PageInfo& /*pageInfo*/) const {}
        virtual void writeFooter(QIODevice* /*dev*/) const {}
        virtual void appendOutput(QIODevice* dev, OcrEngine* engine, const PageInfo& pageInfo, bool firstArea) const = 0;
    };

    OutputEditor(QWidget* parent = nullptr);

    virtual void initialize(OcrEngine* engine);
    virtual void read(int pageNumber, const SourceDocumentPage* page) = 0;
    virtual bool isModified() const = 0;
    virtual void commit() = 0;
    virtual void clear() = 0;
    virtual void setLanguage(const QString& /*lang*/);

    virtual BatchProcessor* createBatchProcessor(const QMap<QString, QVariant>& options) const = 0;

protected:
    OcrEngine* engine() const;

private:
    QPointer<OcrEngine> m_engine;

};

#endif // OUTPUTEDITOR_H
