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 userId;
    private String extraParams;

    public ChartRating(int rating, String chartType, String lang, String pageUrl, String projectId, String viewType, String userId, String extraParams) {
        this.rating = rating;
        this.chartType = chartType;
        this.lang = lang;
        this.pageUrl = pageUrl;
        this.projectId = projectId;
        this.viewType = viewType;
        this.userId = userId;
        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_USERID = "user_id";
    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_USERID, cr.getUserId());
            jsonObject.addProperty(ChartRating.FLD_EXTRAPARAMS, cr.getExtraParams());

            return jsonObject;
        }
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    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;
    }
}

@@ -91,16 +91,42 @@
 ct.Type;
+%0Aimport java.util.Objects;
 %0A%0Apublic
@@ -823,32 +823,1782 @@
 ting() %7B%0A    %7D%0A%0A
+    public String toJSON() %7B%0A        GsonBuilder gsonBuilder = new GsonBuilder();%0A        gsonBuilder%0A                .registerTypeAdapter(ChartRating.class, new ChartRatingSerializer())%0A                .disableHtmlEscaping()%0A                .setPrettyPrinting();%0A        Gson gson = gsonBuilder.create();%0A%0A        return gson.toJson(this);%0A    %7D%0A%0A    /**%0A     * We want only these specific fields to uniquely identify a %7B@link ChartRating%7D%0A     *%0A     * @return  Hashcode%0A     */%0A    @Override%0A    public int hashCode() %7B%0A        int hash = 3;%0A%0A        hash = 17 * hash + Objects.hashCode(this.chartType);%0A        hash = 17 * hash + Objects.hashCode(this.pageUrl);%0A        hash = 17 * hash + Objects.hashCode(this.projectId);%0A        hash = 17 * hash + Objects.hashCode(this.viewType);%0A        hash = 17 * hash + Objects.hashCode(this.userId);%0A        hash = 17 * hash + Objects.hashCode(this.extraParams);%0A%0A        return hash;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        if (obj == null) %7B%0A            return false;%0A        %7D%0A        if (getClass() != obj.getClass()) %7B%0A            return false;%0A        %7D%0A        final ChartRating other = (ChartRating) obj;%0A        if (!Objects.equals(this.chartType, other.chartType)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.pageUrl, other.pageUrl)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.projectId, other.projectId)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.viewType, other.viewType)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.userId, other.userId)) %7B%0A            return false;%0A        %7D%0A        return Objects.equals(this.extraParams, other.extraParams);%0A    %7D%0A%0A
     public JsonE

Implement toJSON and custom hashCode & equals methods for ChartRating