using System.Reflection; using LCU.Library.Internal.IncentiveApiModels.Entities; using LCU.Library.Internal.IncentiveApiModels.Enums; namespace LCU.API.Internal.Operations.IncentiveApi.Models; public class Settings { public Dictionary ActivityStateSet { get; set; } public Dictionary ActivityTypeSet { get; set; } public List AppRoles { get; set; } public IReadOnlyCollection AuthorizedReports { get; set; } public List BusinessLines { get; set; } public Dictionary DepartmentStateSet { get; set; } public Dictionary OrganizationSet { get; set; } public List PayoutProfiles { get; set; } public List Permissions { get; set; } public List ProductDetails { get; } public Product[] ProductSet { get; set; } public List Regions { get; set; } public Dictionary SystemTypeSet { get; set; } public Dictionary UserTypeSet { get; set; } public IReadOnlyCollection Departments { get; set; } public IReadOnlyCollection Employees { get; set; } public DateTime NextBonusPeriod { get; set; } public Settings() { ActivityStateSet = new Dictionary(); ActivityTypeSet = new Dictionary(); ProductSet = (Product[]) Enum.GetValues(typeof(Product)); ProductDetails = ProductDetail.ProductDetails; SystemTypeSet = new Dictionary(); UserTypeSet = new Dictionary(); OrganizationSet = new Dictionary(); BusinessLines = new List(); DepartmentStateSet = new Dictionary(); Permissions = new List(); Regions = Region.Regions; PayoutProfiles = PayoutProfile.ActivePayoutProfiles; foreach (int key in Enum.GetValues(typeof(ActivityState))) { ActivityStateSet[key.ToString()] = Enum.GetName(typeof(ActivityState), key); } foreach (int key in Enum.GetValues(typeof(ActivityType))) { ActivityTypeSet[key.ToString()] = Enum.GetName(typeof(ActivityType), key); } foreach (int key in Enum.GetValues(typeof(SystemType))) { SystemTypeSet[key.ToString()] = Enum.GetName(typeof(SystemType), key); } foreach (int key in Enum.GetValues(typeof(UserType))) { UserTypeSet[key.ToString()] = Enum.GetName(typeof(UserType), key); } foreach (int key in Enum.GetValues(typeof(DepartmentState))) { DepartmentStateSet[key.ToString()] = Enum.GetName(typeof(DepartmentState), key); } foreach (var field in typeof(Organization).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (field.FieldType != typeof(Organization)) { continue; } var org = field.GetValue(field.Name) as Organization; if (org == null) { continue; } OrganizationSet[org.OrgCode] = org.Name; } foreach (var field in typeof(BusinessLine).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (field.FieldType != typeof(BusinessLine)) { continue; } var bl = field.GetValue(field.Name) as BusinessLine; if (bl != null) { BusinessLines.Add(bl); } } AppRoles = Role.GetRolesList(); Permissions = EnumInstances(); } private List EnumInstances() where T : class { var foundInstances = new List(); foreach (var field in typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (field.FieldType != typeof(T)) { continue; } if (field.GetValue(field.Name) is T instance) { foundInstances.Add(instance); } } return foundInstances; } }