// PRE-GENERATED (design session). Pure logic: pick the preset for the current context.
using System;
using System.Collections.Generic;

namespace DansoriEQ.Core.Switching;

public static class SwitchRuleEvaluator
{
    /// <summary>First enabled rule whose trigger subject contains its Match; null if none.</summary>
    public static SwitchRule? Match(IEnumerable<SwitchRule> rules, SwitchContext ctx)
    {
        foreach (var r in rules)
        {
            if (!r.Enabled || string.IsNullOrWhiteSpace(r.Match)) continue;
            var subject = r.Trigger == SwitchTrigger.App ? ctx.AppProcess : ctx.DeviceName;
            if (!string.IsNullOrEmpty(subject) &&
                subject.Contains(r.Match, StringComparison.OrdinalIgnoreCase))
                return r;
        }
        return null;
    }
}
