/*******************************************************************************
***  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_BUDGETING_DEBT_H_
#define DRN_BUDGETING_DEBT_H_

#include <iosfwd>

#include "BudgetedMoney.h"
#include "budgeting_export.h"


namespace drn
{
namespace budgeting
{

struct DRN_BUDGETING_EXPORT Percentage
{
	bool operator<(const Percentage& other) const;
	bool operator<(const double& rate) const;
	/**
	 * @brief Determines if two rates are the same.
	 *
	 * @param other The other rate to compare.
	 *
	 * @return True when the two rates are within the epsilon digit places of each other, false
	 * else wise.
	 */
	bool operator==(const Percentage& other) const;

	/// @brief The number of digits places.
	static const std::int32_t precision_;
	double rate_;
};
/**
 * @brief The representation of an amount of money that is borrowed and how often it occurs.
 */
class DRN_BUDGETING_EXPORT Debt : public BudgetedMoney
{
	pecunia::currency::Money borrowed_;
	Percentage interest_;

public:
	/**
	 * @brief Constructs all member variables to their empty state.
	 */
	Debt();
	Debt(const BudgetSource& source);
	/**
	 * @brief Fully initialises all member variables to their supplied values.
	 *
	 * @exception BudgetItemError When the source is empty.
	 * @exception BudgetItemError When the borrowed is less then zero.
	 * @exception BudgetItemError When the borrowed is not issued in a known currency.
	 * @exception BudgetItemError When the borrowed is less then the minimum payment.
	 * @exception BudgetItemError When the period is not known.
	 * @exception BudgetItemError When the minimum is less than zero.
	 * @exception BudgetItemError When the minimum is not issued in a known currency.
	 * @exception BudgetItemError When the interest rate is less than zero.
	 * @exception BudgetItemError When the next occur date is invalid.
	 *
	 * @param source The source of the debt.
	 * @param minimum The minimum payment required per payment period.
	 * @param period The frequency period of payment for the debt source.
	 * @param nextOccurOn The date the money budget item last occurred on.
	 * @param interest The interest rate applied to the borrowed amount.
	 * @param borrowed The total amount of money borrowed from the debt source.
	 */
	Debt(
		const BudgetSource& source,
		const pecunia::currency::Money& minimum,
		const EventFrequency& period,
		const ::QDate& nextOccurOn,
		const pecunia::currency::Money& borrowed,
		const Percentage& interest
	);
	/**
	 * @brief Equality operator compares all members.
	 *
	 * @param other The other object whose members should all be equal.
	 *
	 * @return When all member variables are the same it'll give true, else false.
	 */
	bool operator==(const Debt& other) const;
	/**
	 * @brief The total amount of money borrowed.
	 */
	const pecunia::currency::Money& borrowed() const;
	/**
	 * @brief The current interest rate for the debt.
	 */
	const Percentage& interest() const;
};

DRN_BUDGETING_EXPORT std::ostream& operator<<(std::ostream& o, const Percentage& p);
DRN_BUDGETING_EXPORT std::ostream& operator<<(std::ostream& o, const Debt& d);

}}

#endif
