package gr.demokritos.iit.ydsapi.model;

import com.google.gson.*;

import java.lang.reflect.Type;

public class ChartRating {
    private int rating;
    private String chartType;
    private String lang;
    private String pageUrl;
    private String projectId;
    private String viewType;
    private String extraParams;

    public ChartRating(int rating, String chartType, String lang, String pageUrl, String projectId, String viewType, String extraParams) {
        this.rating = rating;
        this.chartType = chartType;
        this.lang = lang;
        this.pageUrl = pageUrl;
        this.projectId = projectId;
        this.viewType = viewType;
        this.extraParams = extraParams;
    }

    public ChartRating() {
    }

    public JsonElement toJSONElement() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder
                .registerTypeAdapter(ChartRating.class, new ChartRating.ChartRatingSerializer())
                .disableHtmlEscaping()
                .setPrettyPrinting();
        Gson gson = gsonBuilder.create();

        return gson.toJsonTree(this);
    }

    public static final String FLD_RATING = "rating";
    public static final String FLD_CHARTTYPE = "chart_type";
    public static final String FLD_LANG = "lang";
    public static final String FLD_PAGEURL = "page_url";
    public static final String FLD_PROJECTID = "project_id";
    public static final String FLD_VIEWTYPE = "view_type";
    public static final String FLD_EXTRAPARAMS = "extra_params";

    /**
     * Helper class to serialize as needed in the API
     */
    class ChartRatingSerializer implements JsonSerializer<ChartRating> {

        @Override
        public JsonElement serialize(ChartRating cr, Type type, JsonSerializationContext jsonSerializationContext) {
            final JsonObject jsonObject = new JsonObject();

            jsonObject.addProperty(ChartRating.FLD_RATING, cr.getRating());
            jsonObject.addProperty(ChartRating.FLD_CHARTTYPE, cr.getChartType());
            jsonObject.addProperty(ChartRating.FLD_LANG, cr.getLang());
            jsonObject.addProperty(ChartRating.FLD_PAGEURL, cr.getPageUrl());
            jsonObject.addProperty(ChartRating.FLD_PROJECTID, cr.getProjectId());
            jsonObject.addProperty(ChartRating.FLD_VIEWTYPE, cr.getViewType());
            jsonObject.addProperty(ChartRating.FLD_EXTRAPARAMS, cr.getExtraParams());

            return jsonObject;
        }
    }

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public String getChartType() {
        return chartType;
    }

    public void setChartType(String chartType) {
        this.chartType = chartType;
    }

    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    public String getPageUrl() {
        return pageUrl;
    }

    public void setPageUrl(String pageUrl) {
        this.pageUrl = pageUrl;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public String getViewType() {
        return viewType;
    }

    public void setViewType(String viewType) {
        this.viewType = viewType;
    }

    public String getExtraParams() {
        return extraParams;
    }

    public void setExtraParams(String extraParams) {
        this.extraParams = extraParams;
    }
}

@@ -282,24 +282,51 @@
 g viewType;%0A
+    private String userId;%0A
     private 
@@ -458,24 +458,39 @@
 ng viewType,
+ String userId,
  String extr
@@ -690,24 +690,54 @@
 = viewType;%0A
+        this.userId = userId;%0A
         this
@@ -1515,32 +1515,87 @@
  = %22view_type%22;%0A
+    public static final String FLD_USERID = %22user_id%22;%0A
     public stati
@@ -2446,32 +2446,108 @@
 getViewType());%0A
+            jsonObject.addProperty(ChartRating.FLD_USERID, cr.getUserId());%0A
             json
@@ -2657,32 +2657,174 @@
        %7D%0A    %7D%0A%0A
+    public String getUserId() %7B%0A        return userId;%0A    %7D%0A%0A    public void setUserId(String userId) %7B%0A        this.userId = userId;%0A    %7D%0A%0A
     public int g

Add user ID to the chart rating model