/*******************************************************************************
***  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_BUDGETEDMONEY_H_
#define DRN_BUDGETING_BUDGETEDMONEY_H_

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

#include <iosfwd>

#include "BudgetSource.h"
#include "EventFrequency.h"
#include "budgeting_export.h"


namespace drn
{
namespace budgeting
{

/**
 * @brief Represents a budget item with monetary value that regularly occurs.
 */
class DRN_BUDGETING_EXPORT BudgetedMoney
{
	BudgetSource source_;
	pecunia::currency::Money amount_;
	EventFrequency period_;
	::QDate nextOccurOn_;

public:
	/**
	 * @brief Constructs all member variables to their empty state.
	 */
	BudgetedMoney();
	/**
	 * @brief Constructs all member variables to their empty state apart from the source.
	 *
	 * @exception BudgetItemError When the source is empty.
	 *
	 * @param source The source of the money budget item.
	 */
	BudgetedMoney(const BudgetSource& source);
	/**
	 * @brief Fully initialises all member variables to their supplied values.
	 *
	 * @exception BudgetItemError When the source is empty.
	 * @exception BudgetItemError When the amount is less then zero.
	 * @exception BudgetItemError When the amount is not issued in a known currency.
	 * @exception BudgetItemError When the period is not known.
	 * @exception BudgetItemError When the next occur date is invalid.
	 *
	 * @param source The source of the money budget item.
	 * @param amount The amount the money is for every period.
	 * @param period The frequency period of the event for the money.
	 * @param nextOccurOn The date the money budget item last occurred on.
	 */
	BudgetedMoney(
		const BudgetSource& source,
		const pecunia::currency::Money& amount,
		const EventFrequency& period,
		const ::QDate& nextOccurOn
	);
	virtual ~BudgetedMoney() = default;
	/**
	 * @brief The identifier of the source for the money.
	 */
	const BudgetSource& source() const;
	/**
	 * @brief The amount expected per period for the money.
	 */
	const pecunia::currency::Money& amount() const;
	/**
	 * @brief The frequency at which the money event occurs.
	 */
	const EventFrequency& period() const;
	/**
	 * @brief The date the budgeted money item occurs on next.
	 */
	const ::QDate& nextOccurOn() const;
	/**
	 * @brief Changes the source of the money.
	 *
	 * @exception BudgetItemError When the new source is empty.
	 *
	 * @param source The new source for the money.
	 */
	void setSource(BudgetSource source);
	/**
	 * @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 BudgetedMoney& other) const;
	/**
	 * @brief Inequality operator compares all members.
	 *
	 * @param other The other object whose members should all not be equal.
	 *
	 * @return When all member variables are not the same it'll give true, else false.
	 */
	bool operator!=(const BudgetedMoney& other) const;
	/**
	 * @brief Updates the next occur on date by the event frequency period.
	 *
	 * @exception BudgetItemError When event frequency period is not known.
	 * @exception BudgetItemError When the next occur date is not valid.
	 */
	void updateNextOccurOn();
};

DRN_BUDGETING_EXPORT std::ostream& operator<<(std::ostream& o, const BudgetedMoney& bm);

}}

#endif
