using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; namespace PipefyProspUpdate { public class AppState { private static readonly List suggestions = new(); public DateTime LastUpdated { get; set; } public List? Suggestions { get; set; } = suggestions; public List MesoChangeBoxItems { get; set; } = new(); public List CityChangeBoxItems { get; set; } = new(); public List Users { get; set; } = new(); public List Prospectante { get; set; } = new(); public List Others { get; set; } = new(); public List ProspeccaoFilteredCards { get; set; } = new(); public List recentMutations { get; set; } = new(); public bool filterFlag { get; set; } public int currentItems { get; set; } public string? selectedUF { get; set; } public bool KeepProsp { get; set; } public bool KeepResp { get; set; } private static AppState? _instance; private static readonly string FilePath = SetPath(); public static AppState Instance => _instance ??= Load(); private AppState() { } public static string SetPath() { return $"{System.IO.Path.GetTempPath()}appstate.json"; } public void Save() { var json = JsonConvert.SerializeObject(this, Formatting.Indented); File.WriteAllText(FilePath, json); } private static AppState Load() { if (File.Exists(FilePath)) { var json = File.ReadAllText(FilePath); return JsonConvert.DeserializeObject(json) ?? new AppState(); } return new AppState(); } } }