/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#define SPDLOG_DEBUG_ON
#define SPDLOG_TRACE_ON

#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/pattern_formatter.h>

namespace OpenVulkano
{
	class Logger
	{ //TODO add custom sink for in game/engine console
		static std::vector<spdlog::sink_ptr> SINKS;
		static std::vector<std::weak_ptr<spdlog::logger>> LOGGERS;

	public:
		typedef std::shared_ptr<spdlog::logger> Ptr;

		static Ptr WINDOW;
		static Ptr MANAGER;
		static Ptr RENDER;
		static Ptr PHYSIC;
		static Ptr AUDIO;
		static Ptr DATA;
		static Ptr SCENE;
		static Ptr INPUT;
		static Ptr FILESYS;
		static Ptr AR;
		static Ptr PERF;
		static Ptr APP;

		static void SetupLogger(std::string logFolder = "", const std::string& logFile = "openVulkano.log");

		/**
		 * \brief Creates a new custom logger that writes to the main log file.
		 * \param name The name of the logger
		 * \param reg If set to true the logger can be accessed again with Logger::GetLogger(name)
		 * \return The created logger, if reg = true and a logger with the given name already exists this function will return the old logger.
		 */
		static Ptr CreateLogger(const std::string& name, bool reg = true);

		static Ptr GetLogger(const std::string& name);

		static void RegisterSink(const spdlog::sink_ptr& newSink);
	};

	class CustomThreadNameFormatterFlag : public spdlog::custom_flag_formatter
	{
	public:
		void format(const spdlog::details::log_msg &msg, const std::tm &tmTime, spdlog::memory_buf_t &dest) override;
		std::unique_ptr<spdlog::custom_flag_formatter> clone() const override;
	};

}