using BepInEx.Logging;

namespace MuzikaGromche;

#if DEBUG

// A logger with an API similar to ManualLogSource.
// This logger caches last posted messagee and uses it to deduplicate subsequent messages.
// Use Clear() to forget deduplicated message.
internal class DedupManualLogSource
{
    public ManualLogSource Source;

    object? lastData = null;

    public DedupManualLogSource(ManualLogSource source)
    {
        Source = source;
    }

    public void Log(LogLevel level, object data)
    {
        if (lastData != data)
        {
            lastData = data;
            Source.Log(level, data);
        }
    }

    public void LogFatal(object data)
    {
        Log(LogLevel.Fatal, data);
    }

    public void LogError(object data)
    {
        Log(LogLevel.Error, data);
    }

    public void LogWarning(object data)
    {
        Log(LogLevel.Warning, data);
    }

    public void LogMessage(object data)
    {
        Log(LogLevel.Message, data);
    }

    public void LogInfo(object data)
    {
        Log(LogLevel.Info, data);
    }

    public void LogDebug(object data)
    {
        Log(LogLevel.Debug, data);
    }

    public void Clear()
    {
        lastData = null;
    }

    public void Dispose()
    {
    }
}

#endif
