// PRE-GENERATED (design session). Persists auto-switch rules to switch_rules.json.
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using DansoriEQ.Core.Switching;

namespace DansoriEQ.App.Switching;

public static class SwitchRulesStore
{
    public static List<SwitchRule> Load()
    {
        try
        {
            return File.Exists(AppPaths.SwitchRulesFile)
                ? JsonSerializer.Deserialize<List<SwitchRule>>(File.ReadAllText(AppPaths.SwitchRulesFile)) ?? new()
                : new();
        }
        catch { return new(); }
    }

    public static void Save(List<SwitchRule> rules)
        => File.WriteAllText(AppPaths.SwitchRulesFile, JsonSerializer.Serialize(rules));
}
