using System.Collections.Generic; using System.Linq; using Plugins.Countly.Enums; namespace Plugins.Countly.Models { internal class ConsentModel { #region Fields public readonly string ConsentFormattedName; public readonly string ConsentActualName; public string[] Features; public bool IsConsentGranted; public static HashSet CountlyFeatureConsents; public static HashSet CountlyFeatureGroupConsents; #endregion #region Constructors /// /// Creates a new instance of ConsentModel class and initializes it with the supplied values /// /// /// /// /// public ConsentModel(string formattedName, string name, bool isConsentGranted, string[] features = null) { ConsentFormattedName = formattedName; ConsentActualName = name; IsConsentGranted = isConsentGranted; Features = features; } /// /// Initializes the features list /// static ConsentModel() { CountlyFeatureGroupConsents = new HashSet(); CountlyFeatureConsents = new HashSet { new ConsentModel(FeaturesEnum.Sessions.ToString(), "sessions", true), new ConsentModel(FeaturesEnum.Events.ToString(), "events", true), new ConsentModel(FeaturesEnum.Location.ToString(), "location", true), new ConsentModel(FeaturesEnum.Views.ToString(), "views", true), new ConsentModel(FeaturesEnum.Scrolls.ToString(), "scrolls", true), new ConsentModel(FeaturesEnum.Clicks.ToString(), "clicks", true), new ConsentModel(FeaturesEnum.Forms.ToString(), "forms", true), new ConsentModel(FeaturesEnum.Crashes.ToString(), "crashes", true), new ConsentModel(FeaturesEnum.Attribution.ToString(), "attribution", true), new ConsentModel(FeaturesEnum.Users.ToString(), "users", true), new ConsentModel(FeaturesEnum.Push.ToString(), "push", true), new ConsentModel(FeaturesEnum.StarRating.ToString(), "star-rating", true), new ConsentModel(FeaturesEnum.AccessoryDevices.ToString(), "accessory-devices", true), }; } #endregion #region Methods /// /// Checks consent for a particular feature /// /// /// public static bool CheckConsent(string consentToSearch) { var consent = CountlyFeatureConsents.FirstOrDefault(item => item.ConsentFormattedName == consentToSearch); return consent != null && consent.IsConsentGranted; } /// /// Updates consent for a particular feature /// /// /// public static void UpdateConsent(string consentToUpdate, bool isConsentGranted) { var consent = CountlyFeatureConsents.FirstOrDefault(item => item.ConsentFormattedName == consentToUpdate); if (consent != null) { consent.IsConsentGranted = isConsentGranted; } } #endregion } }