using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;

namespace TakeoutSaaS.Infrastructure.Common.Persistence;

/// <summary>
/// 查询过滤器合并器：用于追加具名 QueryFilter，避免覆盖已有过滤器。
/// </summary>
internal static class QueryFilterCombiner
{
    /// <summary>
    /// 为指定实体追加具名查询过滤器。
    /// </summary>
    /// <typeparam name="TEntity">实体类型。</typeparam>
    /// <param name="modelBuilder">模型构建器。</param>
    /// <param name="filterKey">过滤器键。</param>
    /// <param name="filter">新增过滤器表达式。</param>
    internal static void Combine<TEntity>(ModelBuilder modelBuilder, string filterKey, Expression<Func<TEntity, bool>> filter)
        where TEntity : class
    {
        modelBuilder.Entity<TEntity>().HasQueryFilter(filterKey, filter);
    }
}
