namespace VberAdmin.Web.Models.Search; public class VmSearch { public VmSearch() { Id = "vber_search"; Field = ""; FieldType = FType.S; ExpType = EType.Contains; Items = new List(); } public VmSearch(List items, string id = "vber_search") : this() { Items = items ?? new List(); Id = id; } public VmSearch(string id) : this(new List(), id) { } public string Id { get; set; } public string Field { get; set; } public FType FieldType { get; set; } public EType ExpType { get; set; } private List _items; public List Items { get => _items.Select(SetDefault).ToList(); set => _items = value; } public VmSearch WithItems(List searchItems) { Items = searchItems; return this; } public VmSearch AddItems(List searchItems) { Items ??= new List(); Items.AddRange(searchItems); return this; } public VmSearch AddItem(VmSearchItem searchItem) { Items ??= new List(); Items.Add(searchItem); return this; } public VmSearch WithSearchOption(string field, FType fieldType, EType expType) { Field = field; FieldType = fieldType; ExpType = expType; return this; } private VmSearchItem SetDefault(VmSearchItem item) { item.Search = this; if (item.SelectItem != null) { item.SelectItem.ModalId = Id; } return item; } }