/*******************************************************************************
***  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/>.    ***
*******************************************************************************/
#include <pecunia/Codes.h>
using pecunia::currency::Iso4217Codes;
#include <pecunia/Money.h>
using pecunia::currency::Money;
#include <QString>
using ::QString;
#include <QTest>
// using GTEST_MAIN

#include <chrono>
using namespace std::chrono_literals;
#include <map>
using std::map;
#include <string>
using namespace std::string_literals;
using std::string;

#include <budgeting/Budget.h>
using drn::budgeting::Budget;
using drn::budgeting::BudgetTotals;
#include <budgeting/BudgetSource.h>
using drn::budgeting::BudgetSource;
#include <budgeting/Nontrack.h>
using drn::budgeting::Nontrack;
#include <budgeting/EventFrequency.h>
using drn::budgeting::EventFrequency;
using drn::budgeting::toWeak;
#include <budgeting/Bill.h>
using drn::budgeting::Bill;
#include <budgeting/BillMap.hpp>
using drn::budgeting::BillMap;
#include <budgeting/Goal.h>
using drn::budgeting::Goal;
#include <budgeting/GoalMap.h>
using drn::budgeting::GoalMap;
#include <budgeting/Wage.h>
using drn::budgeting::Wage;
#include <budgeting/WageMap.hpp>
using drn::budgeting::WageMap;
#include <budgeting/Debt.h>
using drn::budgeting::Debt;
using drn::budgeting::Percentage;
#include <budgeting/DebtMap.h>
using drn::budgeting::DebtMap;
#include <foundation/CalendarTime.hpp>
using drn::foundation::Days;


namespace drn
{
namespace budgeting
{
namespace tests
{

struct BudgetItemTotalsUT : QObject
{
	Q_OBJECT

	const WageMap wages_;
	const BillMap bills_;
	const DebtMap debts_;
	const GoalMap goals_;
	const NontrackMap nontracks_;

private slots:
	//{ Constructor Tests

	void constructor_FullInit_ShouldBeCalculated()
	{
		Budget b{
			this->wages_,
			this->bills_,
			this->debts_,
			this->goals_,
			this->nontracks_
		};
		BudgetTotals totals{b, Iso4217Codes::USD, EventFrequency::Monthly, 40h, Days{5}};
		QCOMPARE(totals.wage_, Money(1734, 5118u, Iso4217Codes::USD));
		QCOMPARE(totals.bills_, Money(1391, 6908u, Iso4217Codes::USD));
		QCOMPARE(totals.debts_, Money(1500, 0u, Iso4217Codes::USD));
		QCOMPARE(totals.goals_, Money(933, 3333u, Iso4217Codes::USD));
		QCOMPARE(totals.nontrack_, Money(108, 3333u, Iso4217Codes::USD));
		QCOMPARE(toWeak(totals.period_), toWeak(EventFrequency::Monthly));
		QCOMPARE(totals.remaining_, Money(-2198, 8456u, Iso4217Codes::USD));
	}

	//}

public:
	BudgetItemTotalsUT() :
		QObject{},
		wages_{
			{
				{
					BudgetSource{QStringLiteral("Burger King")},
					Wage{
						BudgetSource{QStringLiteral("Burger King")},
						Money{5, 34u, Iso4217Codes::USD},
						EventFrequency::Hourly,
						{9999, 6, 20}
					}
				},
				{
					BudgetSource{QStringLiteral("McDonald's")},
					Wage{
						BudgetSource{QStringLiteral("McDonald's")},
						Money{5, 34u, Iso4217Codes::USD},
						EventFrequency::Hourly,
						{9999, 6, 20}
					}
				}
			}
		},
		bills_{
			{
				{
					BudgetSource{QStringLiteral("MidCo")},
					Bill{
						BudgetSource{QStringLiteral("MidCo")},
						Money{525, 95u, Iso4217Codes::USD},
						EventFrequency::Monthly,
						{9999, 6, 20}
					}
				},
				{
					BudgetSource{QStringLiteral("Xcel")},
					Bill{
						BudgetSource{QStringLiteral("Xcel")},
						Money{200, 34u, Iso4217Codes::USD},
						EventFrequency::Weekly,
						{9999, 6, 20}
					}
				}
			}
		},
		debts_{
			{
				{
					BudgetSource{QStringLiteral("Home Federal Bank")},
					Debt{
						BudgetSource{QStringLiteral("Home Federal Bank")},
						Money{1000, 0u, Iso4217Codes::USD},
						EventFrequency::Monthly,
						{9999, 6, 20},
						Money{120000, 0u, Iso4217Codes::USD},
						Percentage{3.15}
					}
				},
				{
					BudgetSource{QStringLiteral("Visa")},
					Debt{
						BudgetSource{QStringLiteral("Visa")},
						Money{500, 0u, Iso4217Codes::USD},
						EventFrequency::Monthly,
						{9999, 6, 20},
						Money{30000, 0u, Iso4217Codes::USD},
						Percentage{3.15}
					}
				}
			}
		},
		goals_{
			{
				{
					BudgetSource{QStringLiteral("Computer")},
					Goal{
						BudgetSource{QStringLiteral("Computer")},
						Money{100, 0u, Iso4217Codes::USD},
						EventFrequency::Weekly,
						{9999, 6, 20},
						Money{1000, 0u, Iso4217Codes::USD}
					}
				},
				{
					BudgetSource{QStringLiteral("Vacation")},
					Goal{
						BudgetSource{QStringLiteral("Computer")},
						Money{500, 0u, Iso4217Codes::USD},
						EventFrequency::Monthly,
						{9999, 6, 20},
						Money{5000, 0u, Iso4217Codes::USD}
					}
				}
			}
		},
		nontracks_{
			{
				{
					BudgetSource{QStringLiteral("Discretionary Spending")},
					Nontrack{
						BudgetSource{QStringLiteral("Discretionary Spending")},
						Money{25, 0u, Iso4217Codes::USD},
						EventFrequency::Weekly,
						{9999, 6, 20}
					}
				}
			}
		}
	{}
};

}}}

QTEST_MAIN(drn::budgeting::tests::BudgetItemTotalsUT)
#include "BudgetTotals-unit-tests.moc"
