/*
 * SPDX-FileCopyrightText: Copyright 2024-2025 Open Mobile Platform LLC <community@omp.ru>
 * SPDX-License-Identifier: Proprietary
 */

#pragma once

#include <memory>
#include <QObject>
#include <QTemporaryDir>

namespace Aurora {
namespace WebView {

/**
 * @class PdfPrintResult
 * @brief represents pdf print results
 */
class PdfPrintResult
{
    Q_GADGET

    /// Path to the saved PDF file
    Q_PROPERTY(QString path READ path)

    /// True when the web page has been successfully saved in PDF format
    Q_PROPERTY(bool printResult READ printResult)

public:
    /**
     * @brief Constructs a new PdfPrintResult object with parameters
     * 
     * @param path path to the saved PDF file
     * @param printResult true when the web page has been successfully saved in PDF format
     */
    PdfPrintResult(QString path, bool printResult);

    /**
     * @brief Constructs a new PdfPrintResult object.
     * This constructor is used when print is requested from web content. It creates
     * temporary dir where the document is located at manages its lifetime
     *
     * @param documentName path to the saved PDF file
     * @param browserId browser that generates print result
     */
    PdfPrintResult(QString documentName, int browserId);

    /**
     * @brief Default conctructor for PdfPrintResult object
     * This constructor is declared to register
     * this class in QML
     */
    PdfPrintResult();

    /**
     * @brief Destroys the PdfPrintResult object
     */
    virtual ~PdfPrintResult() = default;

    /// Path to the saved PDF file
    QString path() const;

    /// True when the web page has been successfully saved in PDF format
    bool printResult() const;

    /// Browser that generates print result.
    /// Used if print result is generated by web content.
    int browserId() const;

    /**
     * @brief Invalidate PdfPrintResult object
     * Make path to the document empty.
     * Delete temporary document if it is genereted
     */
    Q_INVOKABLE void release();

private:
    QString m_path;
    bool m_printResult;
    int m_browserId;
    std::shared_ptr<QTemporaryDir> m_tempPrintDir;
};

} // namespace WebView
} // namespace Aurora

Q_DECLARE_METATYPE(Aurora::WebView::PdfPrintResult)
