using System; using UnityEngine; namespace JustTrack { /// /// Represents an experiment assignment. /// #pragma warning disable SA1401 // Fields should be private (public API) public class Assignment { /// /// The config key associated with this assignment. /// public string ConfigKey; /// /// The raw config value for this assignment. /// public string ConfigValue; /// /// The unique identifier of the experiment (UUID format). /// public string ExperimentId; /// /// Whether this assignment is pending activation. /// public bool IsPending; /// /// Initializes a new instance of the class. /// Constructor for Assignment. /// /// The config key. /// The config value. /// The experiment ID. /// Whether the assignment is pending activation. public Assignment(string configKey, string configValue, string experimentId, bool isPending) { this.ConfigKey = configKey; this.ConfigValue = configValue; this.ExperimentId = experimentId; this.IsPending = isPending; } #if UNITY_ANDROID internal static Assignment? FromAndroidObject(AndroidJavaObject pObject) { if (pObject == null) { return null; } try { return new Assignment( pObject.Call("getConfigKey"), pObject.Call("getConfigValue"), pObject.Call("getExperimentId"), pObject.Call("isPending") ); } catch (Exception ex) { throw new InvalidOperationException("Failed to create Assignment from Android object.", ex); } } #endif #if UNITY_IOS [Serializable] private class AssignmentDto { public string ConfigKey = ""; public string ConfigValue = ""; public string ExperimentId = ""; public bool IsPending = false; } internal static Assignment? FromJson(string json) { if (string.IsNullOrEmpty(json)) { return null; } try { AssignmentDto parsed = JsonUtility.FromJson(json); if (parsed == null) { throw new InvalidOperationException("Failed to create Assignment from JSON."); } return new Assignment(parsed.ConfigKey ?? "", parsed.ConfigValue ?? "", parsed.ExperimentId ?? "", parsed.IsPending); } catch (Exception ex) when (ex is not InvalidOperationException) { throw new InvalidOperationException("Failed to create Assignment from JSON.", ex); } } #endif } #pragma warning restore SA1401 }