/*******************************************************************************
***  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 "BankName.h"
using ::QString;
using drn::banking::BankName;

#include <QObject>
using ::QObject;

#include <ostream>
using std::boolalpha;
using std::ostream;
#include <utility>
using std::move;

#include "BankingErrors.h"
using drn::banking::BankError;


BankName::BankName(QString name) :
	value_{move(name)}
{
	if (this->value_.trimmed().isEmpty())
		throw BankError{{}, QObject::tr("The name of a financial institution cannot be empty.")};
}

bool BankName::operator==(const BankName& other) const
{
	return this->value_ == other.value_;
}

bool BankName::operator!=(const BankName& other) const
{
	return ! (*this == other);
}

const QString& BankName::institution() const noexcept
{
	return this->value_;
}

bool BankName::isEmpty() const
{
	return this->value_.isEmpty();
}

bool drn::banking::operator<(const BankName& lhs, const BankName& rhs)
{
	return lhs.institution() < rhs.institution();
}

QString drn::banking::operator+(const QString& value, const BankName& bn)
{
	return value + bn.institution();
}

ostream& drn::banking::operator<<(ostream& o, const BankName& bn)
{
	return o << "Bank Name Institution: (" << bn.institution().toStdString() << ')';
}

QString drn::banking::presentationText(const BankName& bn)
{
	return bn.institution();
}
