using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace PepperDash.Essentials.Core.Config { /// /// Override this and splice on specific room type behavior, as well as other properties /// public class BasicConfig { [JsonProperty("info")] public InfoConfig Info { get; set; } [JsonProperty("devices")] public List Devices { get; set; } [JsonProperty("sourceLists")] public Dictionary> SourceLists { get; set; } [JsonProperty("destinationLists")] public Dictionary> DestinationLists { get; set; } [JsonProperty("tieLines")] public List TieLines { get; set; } [JsonProperty("joinMaps")] public Dictionary JoinMaps { get; set; } public BasicConfig() { Info = new InfoConfig(); Devices = new List(); SourceLists = new Dictionary>(); DestinationLists = new Dictionary>(); TieLines = new List(); JoinMaps = new Dictionary(); } /// /// Checks SourceLists for a given list and returns it if found. Otherwise, returns null /// public Dictionary GetSourceListForKey(string key) { if (string.IsNullOrEmpty(key) || !SourceLists.ContainsKey(key)) return null; return SourceLists[key]; } /// /// Retrieves a DestinationListItem based on the key /// /// key of the item to retrieve /// DestinationListItem if the key exists, null otherwise public Dictionary GetDestinationListForKey(string key) { if (string.IsNullOrEmpty(key) || !DestinationLists.ContainsKey(key)) { return null; } return DestinationLists[key]; } /// /// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null /// /// Key of desired device /// public DeviceConfig GetDeviceForKey(string key) { if (string.IsNullOrEmpty(key)) return null; var deviceConfig = Devices.FirstOrDefault(d => d.Key.Equals(key)); if (deviceConfig != null) return deviceConfig; else { return null; } } } }