/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero 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 Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#ifndef DRN_DESKTOP_UI_INTERNAL_TRANSACTIONWIDGET_H_
#define DRN_DESKTOP_UI_INTERNAL_TRANSACTIONWIDGET_H_

#include <QObject>

#include <set>
#include <vector>

#include <accounting/Account.h>
#include <foundation/Optional.hpp>
#include <foundation/Switch.h>
#include <ui_TransactionWidget.h>


namespace pecunia
{
namespace currency
{

enum class Iso4217Codes : quint16;

}}

namespace drn
{
namespace accounting
{

class Transaction;
class TransactionNumber;

}
namespace desktop_ui
{
namespace internal
{

class TransactionWidget : public QWidget, Ui::TransactionWdgt
{
	Q_OBJECT

	foundation::Switch isDirty_;
	const accounting::AccountCode displayedAccount_;

private slots:
	void markDirty();

public:
	TransactionWidget(const foundation::ObserverPtr<::QWidget>& parent);
	TransactionWidget(
		const accounting::Transaction& transaction,
		const accounting::AccountCode& displayedAccountCode,
		std::vector<accounting::AccountCode> accountCodes,
		const std::set<pecunia::currency::Iso4217Codes>& usableCurrencies,
		const foundation::ObserverPtr<::QWidget>& parent
	);
	bool isDirty() const;
	foundation::Optional<accounting::TransactionNumber> number() const;
	bool shouldRemove() const;
	QString description() const;
	::QDate occurredOn() const;
	bool isDebiting() const;
	bool isCrediting() const;
	QString account() const;
	pecunia::currency::Money amount() const;
	void saved(const foundation::Optional<accounting::TransactionNumber>& posted);
	void setNumber(const accounting::TransactionNumber& txnNum);
	bool isCleared() const;
	bool isReconciled() const;
	const accounting::AccountCode& displayedAccount() const;
	void setErrorMessage(const ::QString& errorMessage);
};

}}}

#endif
