using EonaCat.LogStack.Core;
using System;

namespace EonaCat.LogStack.Boosters;

/// <summary>
/// Context enrichment booster that adds contextual information
/// </summary>
public sealed class ContextEnrichmentBooster : BoosterBase
{
    private readonly Func<LogEventBuilder, LogEventBuilder> _enricher;

    public ContextEnrichmentBooster(Func<LogEventBuilder, LogEventBuilder> enricher)
        : base("ContextEnrichment")
    {
        _enricher = enricher ?? throw new ArgumentNullException(nameof(enricher));
    }

    public override bool Boost(ref LogEventBuilder builder)
    {
        try
        {
            builder = _enricher(builder);
            return true;
        }
        catch
        {
            return true; // Don't filter on enrichment error
        }
    }
}
