/*******************************************************************************
***  This file is part of Pecunia.                                           ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023                        ***
***  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Lesser 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 Lesser General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Lesser General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#include "MoneyTypes.h"
using pecunia::ConversionFunction;
using pecunia::defaultConverter;

#include <stdexcept>
using std::logic_error;
#include <type_traits>
using std::is_floating_point;
using std::is_integral;
using std::is_signed;
using std::is_unsigned;

#include "Codes.h"
using pecunia::currency::Iso4217Codes;
#include "FloatingPoint.h"
using namespace pecunia::literals;
using pecunia::FloatingPoint;
#include "MoneyTypes.h"
using pecunia::FloatingPointBase;
using pecunia::MinorUnit;
using pecunia::precision;
using pecunia::UnitStorage;


static_assert(is_unsigned<MinorUnit>::value, "The MinorUnit must be unsigned.");
static_assert(is_integral<MinorUnit>::value, "The MinorUnit must be an integer.");
static_assert(
	is_floating_point<FloatingPointBase>::value,
	"The FloatingPointBase is not a floating-point type."
);
static_assert(is_signed<UnitStorage>::value, "The UnitStorage must be signed.");
static_assert(is_integral<UnitStorage>::value, "The UnitStorage must be an integral.");

FloatingPoint pecunia::defaultConverter(const Iso4217Codes& from, const Iso4217Codes& to)
{
	if (from == to)
		return 1.0_fp;
	throw logic_error{
		"Default converter only handles conversion when the currencies match."
	};
}

ConversionFunction pecunia::converter{&defaultConverter};
