package io.featureflow.client;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by oliver on 23/05/2016.
 */
public class FeatureFlowContext{

    String key;
    Map<String, ? extends JsonElement> values = new HashMap<>();

    public FeatureFlowContext(String key) {
        this.key = key;
    }

    public static Builder keyedContext(String key){
        return new Builder(key);
    }
    public static Builder context(){
        return new Builder();
    }

    public static class Builder{
        private String key;
        private Map<String, JsonElement> values = new HashMap<>();

        public Builder() {}
        public Builder(String key) {
            this.key = key;
        }

        public Builder withValue(String key, JsonElement value){
            this.values.put(key, value);
            return this;
        }
        public Builder withValue(String key, String value){
            JsonPrimitive jsonValue = new JsonPrimitive(value);
            this.values.put(key, jsonValue);
            return this;
        }
        public Builder withValue(String key, DateTime value){
            JsonPrimitive jsonValue = new JsonPrimitive(toIso(value));
            this.values.put(key, jsonValue);
            return this;
        }
        public Builder withValue(String key, Number value){
            JsonPrimitive jsonValue = new JsonPrimitive(value);
            this.values.put(key, jsonValue);
            return this;
        }
        public FeatureFlowContext build(){
            if(key==null)key = "anonymous";
            FeatureFlowContext context = new FeatureFlowContext(key);
            context.values = values;
            return context;
        }

        protected static String toIso(DateTime date) {
            DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
            String str = fmt.print(date);
            return str;
        }
    }
}

@@ -759,32 +759,121 @@
 ilder();%0A    %7D%0A%0A
+    public Map%3CString,? extends JsonElement%3E getValues() %7B%0A        return values;%0A    %7D%0A%0A
     public stati
@@ -2277,20 +2277,233 @@
 ;%0A        %7D%0A
+        protected static DateTime fromIso(String isoDate) %7B%0A            DateTimeFormatter fmt = ISODateTimeFormat.dateTime();%0A            DateTime dt = fmt.parseDateTime(isoDate);%0A            return dt;%0A        %7D%0A
     %7D%0A%7D%0A

Convert and save context values as targets and lookups, added get targets and target search lookup endpoints