/*
 * Copyright (C) 2014-2022 CZ.NIC
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#pragma once

#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include <QString>

#include "src/common.h" /* MessageDirection */
#include "src/identifiers/account_id_db.h"
#include "src/identifiers/message_id.h"
#include "src/io/exports.h"

class QWidget; /* FOrward declaration. */

/*!
 * @brief Describes full message origin.
 */
class MsgOrigin {
public:
	MsgOrigin(void)
	    : acntIdDb(), msgId(), direction(MSG_RECEIVED), downloaded(false)
	{ }

	MsgOrigin(const AcntIdDb &ai, const MsgId &mi, enum MessageDirection md,
	    bool d)
	    : acntIdDb(ai), msgId(mi), direction(md), downloaded(d)
	{ }

	AcntIdDb acntIdDb; /*!< Account and database set. */
	MsgId msgId; /*!< Message identifier. */
	enum MessageDirection direction; /*!< Whether received or sent. */
	bool downloaded; /*!< Whether already downloaded or not. */
};

class GuiMsgOps {
	Q_DECLARE_TR_FUNCTIONS(GuiMsgOps)

public:
	/*!
	 * @brief Export selected messages to disk.
	 *
	 * @param[in] originList List of messages to be worked with.
	 * @param[in] expFileType Export file type.
	 * @param[in] parent Parent widget.
	 */
	static
	void exportSelectedData(const QList<MsgOrigin> &originList,
	    enum Exports::ExportFileType expFileType, QWidget *parent);

	/*!
	 * @brief Export selected message envelopes as PDF and attachment files.
	 *
	 * @param[in] originList List of messages to be worked with.
	 * @param[in] parent Parent widget.
	 */
	static
	void exportSelectedEnvelopeAndAttachments(
	    const QList<MsgOrigin> &originList, QWidget *parent);

	/*!
	 * @brief Construct a random boundary line.
	 *
	 * @return Boundary line string.
	 */
	static
	QString emailBoundary(void);

	/*!
	 * @brief Sends selected messages as ZFO into default e-mail client.
	 *
	 * @param[in] originList List of messages to be worked with.
	 */
	static
	void createEmailWithZfos(const QList<MsgOrigin> &originList);

	/*!
	 * @brief Sends all attachments of selected messages into default
	 *     e-mail client.
	 *
	 * @param[in] originList List of messages to be worked with.
	 */
	static
	void createEmailWithAllAttachments(const QList<MsgOrigin> &originList);
};
