using Serilog;
using Serilog.Core;
using Serilog.Events;

namespace adas_core.Test.Models;

public class FakeLogger : ILogger
{
    public List<string> Messages { get; } = [];

    public ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
    {
        return this;
    }

    public ILogger ForContext(string propertyName, object? value, bool destructureObjects = false)
    {
        return this;
    }

    public ILogger ForContext<TSource>()
    {
        return this;
    }

    public ILogger ForContext(Type source)
    {
        return this;
    }

    public void Write(LogEvent logEvent)
    {
        Messages.Add(logEvent.RenderMessage());
    }

    public void Write(LogEventLevel level, string messageTemplate, params object?[]? propertyValues)
    {
        // Manejar la situación donde propertyValues es nulo, si es necesario
        Messages.Add(propertyValues == null
            ? messageTemplate
            : string.Format(messageTemplate, propertyValues)); // Por ejemplo, solo añadir el mensaje sin formato
    }


    public void Write<T>(LogEventLevel level, string messageTemplate, T propertyValue)
    {
        Messages.Add(string.Format(messageTemplate, propertyValue));
    }

    public void Write(LogEventLevel level, Exception? exception, string messageTemplate,
        params object?[]? propertyValues)
    {
        Messages.Add(propertyValues == null ? messageTemplate : string.Format(messageTemplate, propertyValues));

        if (exception != null) Messages.Add($"Exception: {exception.Message}");
    }


    public bool IsEnabled(LogEventLevel level)
    {
        return true;
    }

    public void Write<T>(LogEventLevel level, Exception? exception, string messageTemplate, T propertyValue)
    {
        Messages.Add(string.Format(messageTemplate, propertyValue));
        if (exception != null)
            Messages.Add($"Exception: {exception.Message}"); // You might want to include the exception here.
    }
}