namespace ClawdDotNet.Core.Logging;

public sealed record LogEntry(
    DateTime Timestamp,
    LogLevel Level,
    string Module,
    string Message,
    Exception? Exception = null
)
{
    public string Format(string timestampFormat)
    {
        var levelTag = Level switch
        {
            LogLevel.Debug => "DBG",
            LogLevel.Info => "INF",
            LogLevel.Warn => "WRN",
            LogLevel.Error => "ERR",
            _ => "???"
        };

        var line = $"[{Timestamp.ToString(timestampFormat)}] [{levelTag}] {Message}";

        if (Exception is not null)
            line += Environment.NewLine + Exception.ToString();

        return line;
    }
}
