/*******************************************************************************
***  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 "FileStorageErrors.h"
using ::QLatin1String;
using ::QString;
using ::qint64;
using std::exception;
using drn::file_storage::AttributeError;
using drn::file_storage::BinaryFileError;
using drn::file_storage::BudgetFileError;
using drn::foundation::Error;

#include <QObject>
using ::QObject;


BudgetFileError::BudgetFileError(
	const QString& errorString,
	const qint64& lineNumber,
	const qint64& columnNumber,
	const QString& message,
	const exception& root
) :
	Error{
		QObject::tr(
			"The budget file is not valid. %1%2 Error appears at line %3, column %4."
		)
			.arg(message)
			.arg(errorString.isEmpty() ? "" : " " + errorString)
			.arg(lineNumber)
			.arg(columnNumber),
		root
	}
{}

AttributeError::AttributeError(
	const QString& tagName,
	const QLatin1String& attributeName,
	const QString& errorString,
	const qint64& lineNumber,
	const qint64& columnNumber,
	const QString& message,
	const exception& root
) :
	BudgetFileError{
		errorString,
		lineNumber,
		columnNumber,
		QObject::tr("The element tag '%1' attribute '%2' is not valid. %3")
			.arg(tagName)
			.arg(attributeName)
			.arg(message),
		root
	}
{}

BinaryFileError::BinaryFileError(
	const QString& fileName,
	const QString& message,
	const exception root
) :
	Error{
		QObject::tr("The binary file, %1, is not valid. %2.")
			.arg(fileName)
			.arg(message),
		root
	}
{}
