/*******************************************************************************
***  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_RECONCILEDBANKACCOUNT_H_
#define DRN_BANKING_RECONCILEDBANKACCOUNT_H_

#include <pecunia/Money.h>
#include <QDate>

#include <iosfwd>
#include <map>

#include "banking_export.h"
#include "BankAccount.h"
#include <foundation/Optional.hpp>


namespace pecunia
{
namespace currency
{

enum class Iso4217Codes : quint16;

}}

namespace drn
{
namespace accounting
{

class AccountNumber;

}
namespace banking
{

class DRN_BANKING_EXPORT ReconciledBankAccount
{
	BankAccount bankAccount_;
	pecunia::currency::Money balance_;
	foundation::Optional<::QDate> reconciledOn_;

public:
	ReconciledBankAccount() = default;
	ReconciledBankAccount(BankAccount bankAccount, const pecunia::currency::Iso4217Codes& currency);
	ReconciledBankAccount(
		BankAccount bankAccount,
		pecunia::currency::Money balance,
		::QDate reconciledOn
	);
	const BankAccount& bankAccount() const noexcept;
	const pecunia::currency::Money& balance() const noexcept;
	const foundation::Optional<::QDate>& reconciledOn() const noexcept;
	void reconcile(const ::QDate& reconciledOn, const pecunia::currency::Money& balance);
};

struct DRN_BANKING_EXPORT ReconciledBankAccounts : std::map<BankAccount, ReconciledBankAccount>
{
	using std::map<BankAccount, ReconciledBankAccount>::map;

	foundation::Optional<ReconciledBankAccount> find(
		const BankName& bn,
		const accounting::AccountNumber& an
	) const;
};

}}

#endif
