/*******************************************************************************
***  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_BILLENTRYWIDGET_H_
#define DRN_DESKTOP_UI_INTERNAL_BILLENTRYWIDGET_H_

#include <QWidget>

#include <set>

#include <budgeting/BudgetSource.h>
#include <foundation/Optional.hpp>
#include <foundation/Switch.h>
#include <ui_BillEntryWidget.h>


class QDate;
class QString;

namespace pecunia
{
namespace currency
{

enum class Iso4217Codes : quint16;

}}

namespace drn
{
namespace budgeting
{

enum class EventFrequency : quint8;
struct Money;
struct Bill;

}
namespace desktop_ui
{
namespace internal
{

/**
 * @brief A Qt Widget to display a single bill entry.
 */
class BillEntryWidget : public ::QWidget, Ui::BillEntryWidget
{
	Q_OBJECT

	foundation::Switch isDirty_;
	foundation::Optional<budgeting::BudgetSource> original_;

private slots:
	void markDirty();

signals:
	/// @brief Triggered when the monetary value changes.
	void valueChanged();

public:
	explicit BillEntryWidget(const foundation::ObserverPtr<::QWidget>& parent);
	explicit BillEntryWidget(
		const budgeting::Bill& bill,
		const std::set<pecunia::currency::Iso4217Codes>& usableCurrencies,
		const foundation::ObserverPtr<::QWidget>& parent
	);
	const foundation::Optional<budgeting::BudgetSource>& originalSource() const;
	::QString sourceText() const;
	budgeting::BudgetSource source() const;
	pecunia::currency::Money amount() const;
	budgeting::EventFrequency period() const;
	::QDate nextOccurOn() const;
	bool shouldRemove() const;
	bool isDirty() const;
	/**
	 * @brief Updates the widget state to indicate that the entry are saved.
	 */
	void saved();
	void setErrorMessage(const ::QString& message);
	void resetDirty();
};

}}}

#endif
