/*********************************************************************
 * \file   LogMacros.hpp
 *
 * \author Romain BOULLARD
 * \date   May 2026
 *********************************************************************/
#ifndef BIGFOOT_UTILS_LOG_LOGMACROS_HPP
#define BIGFOOT_UTILS_LOG_LOGMACROS_HPP
#include <Utils/Log/Log.hpp>
#include <Utils/Singleton.hpp>

#if defined BIGFOOT_NOT_OPTIMIZED
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...)                                                                        \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_DEBUG(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                   \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_DEBUG(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),            \
                            fmt __VA_OPT__(, ) __VA_ARGS__);                                                           \
        }                                                                                                              \
    } while (0)

#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...)                                                                        \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_TRACE_L3(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_TRACE_L3(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),         \
                               fmt __VA_OPT__(, ) __VA_ARGS__);                                                        \
        }                                                                                                              \
    } while (0)

#define BIGFOOT_LOG_INFO(loggerName, fmt, ...)                                                                         \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                    \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_INFO(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),             \
                           fmt __VA_OPT__(, ) __VA_ARGS__);                                                            \
        }                                                                                                              \
    } while (0)

#define BIGFOOT_LOG_WARN(loggerName, fmt, ...)                                                                         \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                 \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_WARNING(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),          \
                              fmt __VA_OPT__(, ) __VA_ARGS__);                                                         \
        }                                                                                                              \
    } while (0)

#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...)                                                                        \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                   \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_ERROR(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),            \
                            fmt __VA_OPT__(, ) __VA_ARGS__);                                                           \
        }                                                                                                              \
    } while (0)

#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...)                                                                        \
    do                                                                                                                 \
    {                                                                                                                  \
        if (::quill::Logger* logger = ::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().GetLogger(loggerName))       \
        {                                                                                                              \
            QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__);                                                \
        }                                                                                                              \
        else                                                                                                           \
        {                                                                                                              \
            QUILL_LOG_CRITICAL(::Bigfoot::Singleton<::Bigfoot::Log>::GetInstance().RegisterLogger(loggerName),         \
                               fmt __VA_OPT__(, ) __VA_ARGS__);                                                        \
        }                                                                                                              \
    } while (0)
#else
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...)
#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...)
#define BIGFOOT_LOG_INFO(loggerName, fmt, ...)
#define BIGFOOT_LOG_WARN(loggerName, fmt, ...)
#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...)
#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...)
#endif
#endif
