using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
namespace GeViSetEditor.Core.Models
{
///
/// Complete representation of ALL configuration data in .set file
///
public class ComprehensiveConfigFile
{
[JsonIgnore]
public byte[] OriginalData { get; set; }
[JsonPropertyName("fileSize")]
public int FileSize { get; set; }
[JsonPropertyName("header")]
public string Header { get; set; } = "";
[JsonPropertyName("headerNullPrefix")]
public bool HeaderNullPrefix { get; set; }
[JsonPropertyName("rootNodes")]
public List RootNodes { get; set; } = new();
[JsonPropertyName("statistics")]
public ComprehensiveConfigStatistics Statistics { get; set; }
///
/// Get all properties (name-value pairs)
///
[JsonIgnore]
public IEnumerable Properties =>
RootNodes.Where(n => n.NodeType == "property");
///
/// Get all Rules markers with their actions
///
[JsonIgnore]
public IEnumerable RulesSections =>
RootNodes.Where(n => n.NodeType == "marker" && n.Name == "Rules");
///
/// Get property by name
///
public IEnumerable GetProperties(string name) =>
Properties.Where(p => p.Name == name);
///
/// Get copy of original data for writing
///
public byte[] GetDataForWriting()
{
byte[] copy = new byte[OriginalData.Length];
System.Array.Copy(OriginalData, copy, OriginalData.Length);
return copy;
}
}
///
/// A node in the configuration tree
///
public class ConfigNode
{
[JsonPropertyName("startOffset")]
public int StartOffset { get; set; }
[JsonPropertyName("endOffset")]
public int EndOffset { get; set; }
[JsonPropertyName("nodeType")]
public string NodeType { get; set; } = "";
[JsonPropertyName("name")]
public string? Name { get; set; }
[JsonPropertyName("value")]
public object? Value { get; set; }
[JsonPropertyName("valueType")]
public string? ValueType { get; set; }
[JsonPropertyName("children")]
public List Children { get; set; } = new();
///
/// Size in bytes
///
[JsonIgnore]
public int Size => EndOffset - StartOffset;
}
///
/// Statistics about parsed configuration (comprehensive version)
///
public class ComprehensiveConfigStatistics
{
[JsonPropertyName("totalNodes")]
public int TotalNodes { get; set; }
[JsonPropertyName("propertyCount")]
public int PropertyCount { get; set; }
[JsonPropertyName("booleanCount")]
public int BooleanCount { get; set; }
[JsonPropertyName("integerCount")]
public int IntegerCount { get; set; }
[JsonPropertyName("stringCount")]
public int StringCount { get; set; }
[JsonPropertyName("markerCount")]
public int MarkerCount { get; set; }
[JsonPropertyName("rulesCount")]
public int RulesCount { get; set; }
}
}