/**
 *  Triangles
 *  Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, version 3 of the License.
 *
 *  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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <iostream>

/**
 * @class Rect
 * @author POSITIVE MENTAL ATTITUDE
 * @date 06/09/16
 * @file Utility.hpp
 * @brief Helper class for box collision.
 */
struct Rect
{
	float left, right, top, bottom;
};

/**
 * @class Echo
 * @author POSITIVE MENTAL ATTITUDE
 * @date 06/09/16
 * @file Utility.hpp
 * @brief Helper class for stdout/stderr output.
 */
class Echo
{
	public:
		enum
		{
			Empty, Info, Load, Debug, Error
		};
		
		Echo() = default;
		
		template<typename Type, typename... Args>
		static void out(int prefix, Type out, Args... args);

		static void out(std::string debug);
		static void out(float debug);
		static void setLogLevel(int loglevel);

	private:
		static void helper(bool err, std::wstring out);
		
		template <typename T>
		static void helper(bool err, T out);

		template<typename Type, typename... Args>
		static void helper(bool err, const Type out, Args... args);

		static bool printType(int order);
		
		static int _loglevel;
};

template <typename Type>
void Echo::helper(bool err, Type out)
{
	if(err)
		std::cerr << out;
	else
		std::cout << out;
}

template<typename Type, typename... Args>
void Echo::helper(bool err, const Type out, Args... args)
{
	if(err)
		std::cerr << out;
	else
		std::cout << out;

    helper(err, args...);
}

template<typename Type, typename... Args>
void Echo::out(int order, Type out, Args... args)
{
	if(!printType(order))
		return;

	if(order == Error)
	{
		helper(true, out, args...);
		std::cerr << std::endl;
	}
	else
	{
		helper(false, out, args...);
		std::cout << std::endl;
	}
}