#pragma once

#include "colors.h"
#include <sstream>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <ctime>

#define _OUT(expr) {std::ostringstream oss; oss << expr << std::endl; std::cout << oss.str();}
#define LOG(expr) _OUT("[" << BOLD << logger::now() << END_COLOR << "] " << BOLD << expr << END_COLOR)
#define LOG_E(expr) _OUT("[" << RED << logger::now() << END_COLOR << "] " << expr)
#define LOG_W(expr) _OUT("[" << YELLOW << logger::now() << END_COLOR << "] " << expr)
#define LOG_I(expr) _OUT("[" << GREEN << logger::now() << END_COLOR << "] " << expr)
#if LOG_DEBUG
#define LOG_D(expr) _OUT("[" << END_COLOR << logger::now() << END_COLOR << "] " << expr)
#else
#define LOG_D(expr)
#endif
#if LOG_TRACE
#define LOG_T(expr) _OUT("[" << GREY << logger::now() << END_COLOR << "] " << expr)
#else
#define LOG_T(expr)
#endif
#define FATAL(expr) LOG_E(expr); exit(EXIT_FAILURE)

namespace logger {
    inline auto now() {
        const auto tp = std::chrono::system_clock::now();
        const auto timet = std::chrono::system_clock::to_time_t(tp);
        return std::put_time(std::localtime(&timet), "%Y-%m-%d %X");
    }
}
