/*******************************************************************************
***  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/Nontrack.h>
using drn::budgeting::Nontrack;
#include <budgeting/EventFrequency.h>
using drn::budgeting::EventFrequency;


namespace drn
{
namespace budgeting
{
namespace tests
{

struct NontrackUT : QObject
{
	Q_OBJECT

private slots:
	//{ Constructor Tests

	void constructor_Default_ShouldSet()
	{
		const Money amount{0, 0, Iso4217Codes::XXX};
		const EventFrequency period{EventFrequency::Unknown};
		const Nontrack ds{};

		QCOMPARE(ds.amount(), amount);
		QCOMPARE(toWeak(ds.period()), toWeak(period));
	}
	void constructor_ValidParams_ShouldSet()
	{
		const Money amount{5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Hourly};
		const QDate nextOccurOn{9999, 6, 20};
		const Nontrack ds{BudgetSource{QStringLiteral("Discretionary Spending")}, amount, period, nextOccurOn};

		QCOMPARE(ds.amount(), amount);
		QCOMPARE(toWeak(ds.period()), toWeak(period));
		QCOMPARE(ds.nextOccurOn(), nextOccurOn);
	}
	void constructor_InvalidAmount_ShouldThrow()
	{
		const Money amount{-5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Hourly};
		QVERIFY_EXCEPTION_THROWN(
			Nontrack(BudgetSource{QStringLiteral("Discretionary Spending")}, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidPeriod_ShouldThrow()
	{
		const Money amount{5, 34, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Unknown};
		QVERIFY_EXCEPTION_THROWN(
			Nontrack(BudgetSource{QStringLiteral("Discretionary Spending")}, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidAmount_LessThanZero_ShouldThrow()
	{
		const Money amount{-200, 00, Iso4217Codes::USD};
		const EventFrequency period{EventFrequency::Monthly};
		QVERIFY_EXCEPTION_THROWN(
			Nontrack(BudgetSource{QStringLiteral("Discretionary Spending")}, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}
	void constructor_InvalidAmount_UnknownCurrency_ShouldThrow()
	{
		const Money amount{200, 00, Iso4217Codes::XXX};
		const EventFrequency period{EventFrequency::Monthly};
		QVERIFY_EXCEPTION_THROWN(
			Nontrack(BudgetSource{QStringLiteral("Discretionary Spending")}, amount, period, {9999, 6, 20}),
			BudgetItemError
		);
	}

	//}
};

}}}

QTEST_MAIN(drn::budgeting::tests::NontrackUT)
#include "Nontrack-unit-tests.moc"
