#pragma once

#include "deimos/core/base.h"

namespace deimos
{

class IWriter;

struct FormatArg
{
    enum Type : uint8_t
    {
        kInteger,
        kUnsignedInteger,
        kString,
    };

    Type type;

    union
    {
        int64_t     integer;
        uint64_t    unsigned_integer;

        // @Todo Use string views
        Span<const char> string;
    };

    explicit FormatArg(std::signed_integral auto value) :
        type{kInteger},
        integer{value}
    {}

    explicit FormatArg(std::unsigned_integral auto value) :
        type{kUnsignedInteger},
        unsigned_integer{value}
    {}

    explicit FormatArg(Span<const char> value) :
        type{kString},
        string{value}
    {}

    explicit FormatArg(gsl::czstring value) :
        type{kString},
        string{value, (int64_t)__builtin_strlen(value)}
    {}
};

template<typename T>
concept Formattable = requires (T value) { FormatArg(value); };

void FormatVa(IWriter*, gsl::czstring fmt, Span<const FormatArg>);

template<Formattable... Args>
void Format(IWriter* writer, gsl::czstring fmt, Args&&... args)
{
    FormatVa(writer, fmt, { FormatArg(std::forward<Args>(args))... });
}

} // namespace deimos