/*********************************************************************
 * \file   EASTLFormatters.hpp
 *
 * \author Romain BOULLARD
 * \date   December 2025
 *********************************************************************/
#ifndef BIGFOOT_UTILS_LOG_EASTLFORMATTERS_HPP
#define BIGFOOT_UTILS_LOG_EASTLFORMATTERS_HPP
#include <Utils/TargetMacros.h>

#if defined(BIGFOOT_NOT_OPTIMIZED)
#include <quill/DeferredFormatCodec.h>
#endif

#include <EASTL/string.h>
#include <EASTL/string_view.h>

#include <format>

// STRING

template<>
struct std::formatter<eastl::string>
{
    constexpr auto parse(std::format_parse_context& ctx)
    {
        return ctx.begin();
    }

    template<typename FormatContext>
    auto format(const eastl::string& p_string, FormatContext& ctx) const
    {
        return std::format_to(ctx.out(), "{}", p_string.c_str());
    }
};

#if defined BIGFOOT_NOT_OPTIMIZED
template<>
struct fmtquill::formatter<eastl::string>
{
    constexpr auto parse(format_parse_context& ctx)
    {
        return ctx.begin();
    }

    auto format(const eastl::string& p_string, format_context& ctx) const
    {
        return fmtquill::format_to(ctx.out(), "{}", p_string.c_str());
    }
};

template<>
struct quill::Codec<eastl::string>: quill::DeferredFormatCodec<eastl::string>
{
};
#endif

// STRING_VIEW

template<>
struct std::formatter<eastl::string_view>
{
    constexpr auto parse(std::format_parse_context& ctx)
    {
        return ctx.begin();
    }

    template<typename FormatContext>
    auto format(const eastl::string_view& p_stringView, FormatContext& ctx) const
    {
        return std::format_to(ctx.out(), "{}", p_stringView.data());
    }
};

#if defined BIGFOOT_NOT_OPTIMIZED
template<>
struct fmtquill::formatter<eastl::string_view>
{
    constexpr auto parse(format_parse_context& ctx)
    {
        return ctx.begin();
    }

    auto format(const eastl::string_view& p_stringView, format_context& ctx) const
    {
        return fmtquill::format_to(ctx.out(), "{}", p_stringView.data());
    }
};

template<>
struct quill::Codec<eastl::string_view>: quill::DeferredFormatCodec<eastl::string_view>
{
};
#endif
#endif
