/*******************************************************************************
***  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_BANKACCOUNTSWIDGET_H_
#define DRN_DESKTOP_UI_INTERNAL_BANKACCOUNTSWIDGET_H_

#include <QWidget>

#include <set>

#include <banking/BankAccountType.h>
#include <foundation/ObserverPtr.hpp>
#include <ui_BankAccountsWidget.h>


namespace drn
{
namespace accounting
{

class AccountNumber;
class AccountCode;

}
namespace banking
{

struct BankAccount;
class BankName;

}
namespace foundation
{

template<typename>
class Optional;

}
namespace desktop_ui
{
namespace internal
{
namespace tests
{

class BankAccountsWidgetUT;

}

class BankAccountsWidget : public ::QWidget, Ui::BankAccountsWidget
{
	Q_OBJECT

	friend tests::BankAccountsWidgetUT;

	foundation::Optional<int> findBankIndex(const banking::BankName& bn);

	std::set<banking::BankAccountType> accountTypes_;

private slots:
	void onBankCurrentIndexChanged(const qint32 index);
	void onAccountCodesCurrentIndexChanged(const qint32 index);
	void onTypeCurrentIndexChanged(const qint32 index);

public slots:
	void lookedUpBankAccounts(std::set<banking::BankAccountType> accountTypes);

signals:
	/**
	 * @brief Triggered when the user changes the current bank selected.
	 *
	 * @param bn The name of the bank that was selected.
	 */
	void lookUpBankAccounts(const banking::BankName& bn);
	void changedBankName(const foundation::Optional<banking::BankName>& bn);
	void changedAccountNumber(const foundation::Optional<accounting::AccountNumber>& an);
	/**
	 * @brief Triggered when the user changes the current bank account type selected.
	 *
	 * @param sat The bank account type selected.
	 */
	void changedBankAccountType(const banking::SupportedAccountTypes& sat);

public:
	BankAccountsWidget(const foundation::ObserverPtr<::QWidget>& parent);
	BankAccountsWidget(
		const std::set<banking::BankName>& banks,
		const foundation::Optional<std::set<banking::SupportedAccountTypes>>& accountTypes,
		const foundation::ObserverPtr<::QWidget>& parent
	);
	std::set<banking::BankName> banks() const noexcept;
	foundation::Optional<banking::BankName> bank() const noexcept;
	foundation::Optional<accounting::AccountCode> accountCode() const noexcept;
	foundation::Optional<banking::SupportedAccountTypes> type() const noexcept;
	void setBanks(const std::set<banking::BankName>& banks);
	void setBank(const foundation::Optional<banking::BankName>& bn);
	void setBankAccount(const banking::BankAccount& ba);
	void setSupportedAccountTypes(const std::set<banking::SupportedAccountTypes>& sats);
	void setSupportedAccountType(const banking::SupportedAccountTypes& sat);
	void hideAccountCodes();
	void showAccountCodes();
	void enableSupportedAccountTypes();
	void disableSupportedAccountTypes();
	void setReadOnly(const bool isReadOnly);
	void setDescription(const foundation::Optional<::QString>& description);
};

}}}

#endif
