internal void AddFlag(FeatureFlag flag, JToken value, int?variation, EvaluationReason reason,
                              bool detailsOnlyIfTracked)
        {
            _flagValues[flag.Key] = value;
            var meta = new FlagMetadata
            {
                Variation            = variation,
                DebugEventsUntilDate = flag.DebugEventsUntilDate
            };

            if (!detailsOnlyIfTracked || flag.TrackEvents || flag.DebugEventsUntilDate != null)
            {
                meta.Version = flag.Version;
                meta.Reason  = reason;
            }
            if (flag.TrackEvents)
            {
                meta.TrackEvents = true;
            }
            _flagMetadata[flag.Key] = meta;
        }
        // This method is defined with internal scope because 1. we don't want application code to use JToken any more and 2. extra
        // metadata fields like trackEvents aren't relevant to the main external use case for the builder (testing server-side code)
        internal FeatureFlagsStateBuilder AddFlag(string flagKey, JToken value, int?variationIndex, EvaluationReason reason, int flagVersion, bool flagTrackEvents, long?flagDebugEventsUntilDate)
        {
            _flagValues[flagKey] = value;
            var meta = new FlagMetadata
            {
                Variation            = variationIndex,
                DebugEventsUntilDate = flagDebugEventsUntilDate
            };

            if (!_detailsOnlyIfTracked || flagTrackEvents || flagDebugEventsUntilDate != null)
            {
                meta.Version = flagVersion;
                meta.Reason  = _withReasons ? reason : null;
            }
            if (flagTrackEvents)
            {
                meta.TrackEvents = true;
            }
            _flagMetadata[flagKey] = meta;
            return(this);
        }