/*******************************************************************************
***  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_ACCOUNTENTRYWIDGET_H_
#define DRN_DESKTOP_UI_INTERNAL_ACCOUNTENTRYWIDGET_H_

#include <QWidget>
#include <QString>

#include <set>

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


namespace pecunia
{
namespace currency
{

enum class Iso4217Codes : quint16;
class Money;

}}

namespace drn
{
namespace banking
{

enum class SupportedAccountTypes;

}
namespace foundation
{

template<typename>
class ObserverPtr;

}
namespace desktop_ui
{
namespace internal
{

class AccountEntryWidget : public ::QWidget, Ui::AccountEntryWdgt
{
	Q_OBJECT

	void markDirty();

	foundation::Switch isDirty_;
	foundation::Switch isEditable_;
	foundation::Optional<accounting::AccountCode> original_;
	bool isOriginallyClosed_;

public:
	AccountEntryWidget(
		foundation::Optional<accounting::AccountCode> original,
		const bool isClosed,
		const accounting::AccountTypes at,
		const pecunia::currency::Money& balance,
		const std::set<accounting::AccountNumber>& potentialParents,
		const std::set<pecunia::currency::Iso4217Codes>& usableCurrencies,
		const foundation::ObserverPtr<::QWidget>& parent
	);
	AccountEntryWidget(
		foundation::Optional<accounting::AccountCode> original,
		const bool isClosed,
		const foundation::Optional<accounting::AccountTypes> at,
		const pecunia::currency::Money& balance,
		const std::set<accounting::AccountNumber>& potentialParents,
		const std::set<pecunia::currency::Iso4217Codes>& usableCurrencies,
		const foundation::Optional<banking::SupportedAccountTypes>& bankAccountType,
		const foundation::ObserverPtr<::QWidget>& parent
	);
	bool isDirty() const noexcept;
	foundation::Optional<accounting::AccountCode> original() const noexcept;
	bool isOriginallyClosed() const noexcept;
	static const ::QString& newAccountCodeText();
	accounting::AccountNumber::ValueType number() const;
	::QString name() const;
	foundation::Optional<accounting::AccountNumber::ValueType> parentNumber() const;
	bool isClosed() const;
	bool isRemoved() const;
	::QString type() const;
	pecunia::currency::Money balance() const;
	::QString accountCodeText() const;
	bool isEmptyCode() const;
	void saved(accounting::AccountCode ac);
	void setErrorMessage(const ::QString& error);
	void addParentableAccountNumber(const accounting::AccountNumber& an);
	void resetDirtyFlag();
	foundation::Optional<banking::SupportedAccountTypes> bankAccountType() const;
	void setEditable(const bool isEditable);
};

}}}

#endif
