/*******************************************************************************
***  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 <qt-mocks/Matchers.h>
using qt_mocks::equals;
// using QVERIFY_THAT;
// using QVERIFY_EXCEPTION_THROWN;
#include <QDate>
using ::QDate;
#include <QObject>
using ::QObject;
// using Q_OBJECT
#include <QTest>
// using QTEST_MAIN

#include <budgeting/BudgetItemDue.h>
using drn::budgeting::BudgetItemDue;
#include <budgeting/BudgetItemIdentifier.h>
using drn::budgeting::BudgetItemIdentifier;
#include <budgeting/BudgetItemTypes.h>
using drn::budgeting::BudgetItemTypes;
#include <budgeting/BudgetSource.h>
using drn::budgeting::BudgetSource;


namespace drn
{
namespace budgeting
{
namespace tests
{

struct BudgetItemDueUT : QObject
{
	Q_OBJECT

private slots:
	//{ constructor Tests

	void constructor_default_ShouldBeDefaults()
	{
		const Money amount{};
		const BudgetItemTypes bit{BudgetItemTypes::Unknown};
		const BudgetSource bs{};
		const BudgetItemIdentifier id{bit, bs};
		const QDate dueOn{};
		const BudgetItemDue bid{};
		QVERIFY_THAT(bid.amount_, equals(amount));
		QVERIFY_THAT(bid.id_, equals(id));
		QVERIFY_THAT(bid.dueOn_, equals(dueOn));
	}

	void constructor_fullInit_ShouldBeValues()
	{
		const Money amount{123, 4500u, Iso4217Codes::USD};
		const BudgetItemTypes bit{BudgetItemTypes::Bill};
		const BudgetSource bs{"Electricity"};
		const BudgetItemIdentifier id{bit, bs};
		const QDate dueOn{2020, 12, 6};
		const BudgetItemDue bid{id, amount, dueOn};
		QVERIFY_THAT(bid.amount_, equals(amount));
		QVERIFY_THAT(bid.id_, equals(id));
		QVERIFY_THAT(bid.dueOn_, equals(dueOn));
	}

	//}

	//{ operator< Tests

	void operatorLessThan_typeLessThan_ShouldBeTrue()
	{
		const BudgetItemDue bid0{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		const BudgetItemDue bid1{
			BudgetItemIdentifier{BudgetItemTypes::Wage, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		QVERIFY_TRUE(bid0 < bid1);
		QVERIFY_FALSE(bid1 < bid0);
	}

	void operatorLessThan_sourceLessThan_ShouldBeTrue()
	{
		const BudgetItemDue bid0{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		const BudgetItemDue bid1{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"bark"}},
			Money{123, 4500u,
			Iso4217Codes::USD}, {2020, 12, 6}
		};
		QVERIFY_TRUE(bid0 < bid1);
		QVERIFY_FALSE(bid1 < bid0);
	}

	void operatorLessThan_amountLessThan_ShouldBeTrue()
	{
		const BudgetItemDue bid0{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{23, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		const BudgetItemDue bid1{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		QVERIFY_TRUE(bid0 < bid1);
		QVERIFY_FALSE(bid1 < bid0);
	}

	void operatorLessThan_dueLessThan_ShouldBeTrue()
	{
		const BudgetItemDue bid0{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 5}
		};
		const BudgetItemDue bid1{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		QVERIFY_TRUE(bid0 < bid1);
		QVERIFY_FALSE(bid1 < bid0);
	}

	void operatorLessThan_nothingLessThan_ShouldBeFalse()
	{
		const BudgetItemDue bid0{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		const BudgetItemDue bid1{
			BudgetItemIdentifier{BudgetItemTypes::Bill, BudgetSource{"acorn"}},
			Money{123, 4500u, Iso4217Codes::USD},
			{2020, 12, 6}
		};
		QVERIFY_FALSE(bid0 < bid1);
		QVERIFY_FALSE(bid1 < bid0);
	}

	//}
};


}}}

QTEST_MAIN(drn::budgeting::tests::BudgetItemDueUT)
#include "BudgetItemDue-unit-tests.moc"
