using EonaCat.LogStack.Core;
using System;

namespace EonaCat.LogStack.Boosters;

/// <summary>
/// Property filter booster that includes/excludes events based on properties
/// </summary>
public sealed class PropertyFilterBooster : BoosterBase
{
    private readonly Func<LogEventBuilder, bool>? _includeFilter;
    private readonly Func<LogEventBuilder, bool>? _excludeFilter;

    public PropertyFilterBooster(
        Func<LogEventBuilder, bool>? includeFilter = null,
        Func<LogEventBuilder, bool>? excludeFilter = null)
        : base("PropertyFilter")
    {
        _includeFilter = includeFilter;
        _excludeFilter = excludeFilter;
    }

    public override bool Boost(ref LogEventBuilder builder)
    {
        // If include filter is specified and returns false, skip
        if (_includeFilter != null && !_includeFilter(builder))
        {
            return false;
        }

        // If exclude filter is specified and returns true, skip
        if (_excludeFilter != null && _excludeFilter(builder))
        {
            return false;
        }

        return true;
    }
}
