using Mlaumcherb.Client.Avalonia.холопы;

namespace Mlaumcherb.Client.Avalonia.классы;

public static class Rules
{
    public static bool Check(ICollection<Rule>? rules, ICollection<string> features)
    {
        if(rules is null || rules.Count == 0)
            return true;
        
        bool allowed = false;
        foreach (var r in rules)
        {
            if (r.os != null && !PlatformHelper.CheckOs(r.os)) 
                continue;
            
            if (r.features == null)
                allowed = r.action == "allow";
            else
            {
                foreach (var feature in features)
                {
                    if (r.features.TryGetValue(feature, out bool is_enabled))
                    {
                        if (is_enabled)
                        {
                            allowed = r.action == "allow";
                        }
                    }
                }
            }
            
            if(allowed)
                break;
        }

        return allowed;
    }
}