/*******************************************************************************
***  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 <QTest>
// using QTEST_MAIN

#include <string>
using namespace std::string_literals;
using std::string;

#include <budgeting/BudgetingErrors.h>
using drn::budgeting::BudgetItemError;
#include <budgeting/BudgetSource.h>
using drn::budgeting::BudgetSource;
#include <budgeting/Wage.h>
using drn::budgeting::Wage;
#include <budgeting/EventFrequency.h>
using drn::budgeting::EventFrequency;
using drn::budgeting::toWeak;


namespace drn
{
namespace budgeting
{
namespace tests
{

struct WageUT : QObject
{
	Q_OBJECT

private slots:
	//{ Constructor Tests

	void constructor_Default_ShouldSet()
	{
		const BudgetSource source{};
		const Money amount{0, 0, Iso4217Codes::XXX};
		const EventFrequency period{EventFrequency::Unknown};
		const Wage si{};

		QCOMPARE(si.source(), source);
		QCOMPARE(si.amount(), amount);
		QCOMPARE(toWeak(si.period()), toWeak(period));
	}
	void constructor_ValidParams_ShouldSet()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Hourly};
		const QDate nextOccurOn{9999, 6, 20};
		const Wage si{source, amount, period, nextOccurOn};

		QCOMPARE(si.source(), source);
		QCOMPARE(si.amount(), amount);
		QCOMPARE(toWeak(si.period()), toWeak(period));
		QCOMPARE(si.nextOccurOn(), nextOccurOn);
	}
	void constructor_InvalidAmount_ShouldThrow()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{-5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Hourly};
		QVERIFY_EXCEPTION_THROWN(
			Wage(source, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidPeriod_ShouldThrow()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Unknown};
		QVERIFY_EXCEPTION_THROWN(
			Wage(source, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidSource_ShouldThrow()
	{
		const BudgetSource source{};
		const Money amount{200, 00, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Monthly};

		QVERIFY_EXCEPTION_THROWN(
			Wage(source, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidAmount_LessThanZero_ShouldThrow()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{-200, 00, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Monthly};
		QVERIFY_EXCEPTION_THROWN(
			Wage(source, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidAmount_UnknownCurrency_ShouldThrow()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{200, 00, Iso4217Codes::XXX};
		const EventFrequency period{EventFrequency::Monthly};
		QVERIFY_EXCEPTION_THROWN(
			Wage(source, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}

	//}

	//{ setSource Tests

	void setSource_ValidParams_ShouldSet()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{200, 00, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Monthly};
		Wage i{source, amount, period, {9999, 6, 20}};
		const BudgetSource newSource{"Burger King"};
		i.setSource(newSource);

		QCOMPARE(i.source(), newSource);
	}
	void setSource_InvalidSource_ShouldThrow()
	{
		const BudgetSource source{"McDonald's"};
		const Money amount{200, 00, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Monthly};
		Wage i{source, amount, period, {9999, 6, 20}};
		const BudgetSource newSource{};

		QVERIFY_EXCEPTION_THROWN(i.setSource(newSource), BudgetItemError);
	}

	//}
};

}}}

QTEST_MAIN(drn::budgeting::tests::WageUT)
#include "Wage-unit-tests.moc"
