using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace GeViSetEditor.Core.Models { /// /// Enhanced representation of .set file with full configuration structure /// Preserves original binary data while exposing parsed configuration /// public class EnhancedSetFile { /// /// Complete original file data - preserved for round-trip /// [JsonIgnore] public byte[] OriginalData { get; set; } /// /// File size in bytes /// [JsonPropertyName("fileSize")] public int FileSize { get; set; } /// /// Header string (usually "GeViSoft Parameters") /// [JsonPropertyName("header")] public string Header { get; set; } = ""; /// /// Configuration items (key-value pairs) /// [JsonPropertyName("configItems")] public List ConfigItems { get; set; } = new(); /// /// Action mappings (trigger -> action rules) /// [JsonPropertyName("actionMappings")] public List ActionMappings { get; set; } = new(); /// /// Section names found in the file /// [JsonPropertyName("sectionNames")] public List SectionNames { get; set; } = new(); /// /// Statistics about the parsed configuration /// [JsonPropertyName("statistics")] public ConfigStatistics Statistics => new ConfigStatistics { TotalConfigItems = ConfigItems.Count, TotalActionMappings = ActionMappings.Count, TotalSectionNames = SectionNames.Count, TotalActions = ActionMappings.Sum(m => m.Actions.Count), ConfigItemsByType = ConfigItems .GroupBy(i => i.ValueType) .ToDictionary(g => g.Key, g => g.Count()), ActionsPerMapping = ActionMappings .GroupBy(m => m.Actions.Count) .OrderBy(g => g.Key) .ToDictionary(g => g.Key, g => g.Count()) }; /// /// Get a clean copy of the original data for writing /// public byte[] GetDataForWriting() { byte[] copy = new byte[OriginalData.Length]; System.Array.Copy(OriginalData, copy, OriginalData.Length); return copy; } } /// /// Configuration item (key-value pair) /// public class ConfigItemEntry { [JsonPropertyName("fileOffset")] public int FileOffset { get; set; } [JsonPropertyName("key")] public string Key { get; set; } = ""; [JsonPropertyName("value")] public object Value { get; set; } [JsonPropertyName("valueType")] public string ValueType { get; set; } = ""; } /// /// Section name found in the file /// public class SectionNameEntry { [JsonPropertyName("fileOffset")] public int FileOffset { get; set; } [JsonPropertyName("name")] public string Name { get; set; } = ""; } /// /// Statistics about parsed configuration /// public class ConfigStatistics { [JsonPropertyName("totalConfigItems")] public int TotalConfigItems { get; set; } [JsonPropertyName("totalActionMappings")] public int TotalActionMappings { get; set; } [JsonPropertyName("totalSectionNames")] public int TotalSectionNames { get; set; } [JsonPropertyName("totalActions")] public int TotalActions { get; set; } [JsonPropertyName("configItemsByType")] public Dictionary ConfigItemsByType { get; set; } = new(); [JsonPropertyName("actionsPerMapping")] public Dictionary ActionsPerMapping { get; set; } = new(); } }