/*******************************************************************************
***  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_BANKING_BANK_H_
#define DRN_BANKING_BANK_H_

#include <iosfwd>
#include <set>

#include <QString>

#include <accounting/AccountCode.h>
#include "banking_export.h"
#include "BankName.h"


namespace drn
{
namespace banking
{

/**
 * @brief A representation of a financial institution.
 */
class DRN_BANKING_EXPORT Bank
{
	std::set<accounting::AccountNumber> accountNumbers_; // TODO: replace with std::set<banking::BankAccountType> and remove bankAccountTypes_ from BankLedgers
	bool isClosed_;

public:
	/**
	 * @brief Default constructor initialising all members to empty.
	 */
	Bank() = default;
	/**
	 * @brief Full and partial initialising constructor.
	 *
	 * @exception BankError When the supplied name is empty.
	 *
	 * @param name The name of the financial institution.
	 * @param numbers The general ledger account numbers associated with the financial institution.
	 * @param isClosed The flag to indicate if a financial institution is closed for usage.
	 */
	explicit Bank(
		BankName name,
		std::set<accounting::AccountNumber> numbers = {},
		const bool isClosed = false
	);
	/**
	 * @brief An accessor for all the accounts associated with this financial institution.
	 *
	 * @return The account numbers of the associated accounts, empty when not set.
	 */
	const std::set<accounting::AccountNumber>& accounts() const;
	/**
	* @brief An accessor for the flag to indicate if the financial institution is closed for usage.
	*
	* @return Gives true when the financial institution is closed.
	*/
	const bool& isClosed() const;
	/**
	 * @brief Marks the financial institution as closed for usage.
	 *
	 * @exception BankError When the financial institution is already closed.
	 */
	void close();
	/**
	 * @brief Marks the financial institution as open for usage.
	 *
	 * @exception BankError When the financial institution is already opened.
	 */
	void open();
	/**
	 * @brief Adds an account number to associate with the financial institution.
	 *
	 * @param number The account number to add.
	 */
	void add(accounting::AccountNumber number);
	/**
	 * @brief Removes an account number from the association with the financial institution.
	 *
	 * @exception BankError When the account number to remove is not associated with the financial
	 * institution.
	 *
	 * @param number The number to remove.
	 */
	void remove(const accounting::AccountNumber& number);

	/// The name of the financial institution, empty when not set.
	BankName name_;
};

DRN_BANKING_EXPORT bool operator==(const Bank& lhs, const Bank& rhs);
DRN_BANKING_EXPORT bool operator!=(const Bank& lhs, const Bank& rhs);
DRN_BANKING_EXPORT std::ostream& operator<<(std::ostream& o, const Bank& b);

}}

// HACK: This shouldn't be here any more, but when moved to the BankName declaration file the
// project fails to compile.
Q_DECLARE_METATYPE(drn::banking::BankName)

#endif
