namespace HaWeb.Models; using HaWeb.XMLParser; public class ItemsCollection { public string Name { get; private set; } public Dictionary Items { get; private set; } public bool Searchable { get; private set; } public IXMLRoot Root { get; private set; } public Func, Dictionary>?>? GroupingsGeneration { get; private set; } public Func, Dictionary>?>? SortingsGeneration { get; private set; } public Dictionary>? Groupings { get; private set; } public Dictionary>? Sortings { get; private set; } public ItemsCollection( string name, bool searchable, IXMLRoot root, Func, Dictionary>?>? groupingsFunc = null, Func, Dictionary>?>? sortingsFunc = null ) { this.Name = name; this.Searchable = searchable; this.Root = root; this.GroupingsGeneration = groupingsFunc; this.SortingsGeneration = sortingsFunc; this.Items = new Dictionary(); } public void GenerateGroupings( Func, Dictionary>?>? groupingsFunc = null ) { if (groupingsFunc != null) this.GroupingsGeneration = groupingsFunc; if (this.GroupingsGeneration != null && this.Items.Any()) this.Groupings = GroupingsGeneration(this.Items.Values.ToList()); } public void GenerateSortings( Func, Dictionary>?>? sortingsFunc = null ) { if (sortingsFunc != null) this.SortingsGeneration = sortingsFunc; if (this.SortingsGeneration != null && this.Items.Any()) this.Sortings = SortingsGeneration(this.Items.Values.ToList()); } }