package org.tndata.android.compass.model;

import android.os.Parcel;

import com.google.gson.annotations.SerializedName;


/**
 * Model class for user goals.
 *
 * @author Ismael Alonso
 * @version 1.0.0
 */
public class UserGoal extends Goal{
    public static final String TYPE = "usergoal";


    //Values retrieved from the API
    @SerializedName("goal")
    private TDCGoal mGoal;
    @SerializedName("primary_category")
    private long mPrimaryCategoryId;


    /*---------*
     * GETTERS *
     *---------*/

    public TDCGoal getGoal(){
        return mGoal;
    }

    @Override
    public long getContentId(){
        return mGoal.getId();
    }

    @Override
    public String getTitle(){
        return mGoal.getTitle();
    }

    public String getDescription(){
        return mGoal.getDescription();
    }

    public String getHTMLDescription(){
        return mGoal.getHTMLDescription();
    }

    public long getPrimaryCategoryId(){
        return mPrimaryCategoryId;
    }

    @Override
    protected String getType(){
        return TYPE;
    }


    /*---------*
     * UTILITY *
     *---------*/

    @Override
    public void init(){

    }

    @Override
    public String toString(){
        return "UserGoal #" + getId() + " (" + mGoal.toString() + ")";
    }

    @Override
    public int describeContents(){
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags){
        super.writeToParcel(dest, flags);
        dest.writeParcelable(mGoal, flags);
        dest.writeLong(mPrimaryCategoryId);
    }

    public static final Creator<UserGoal> CREATOR = new Creator<UserGoal>(){
        @Override
        public UserGoal createFromParcel(Parcel source){
            return new UserGoal(source);
        }

        @Override
        public UserGoal[] newArray(int size){
            return new UserGoal[size];
        }
    };

    private UserGoal(Parcel src){
        super(src);
        mGoal = src.readParcelable(TDCGoal.class.getClassLoader());
        mPrimaryCategoryId = src.readLong();
    }
}

@@ -458,16 +458,170 @@
 oryId;%0A%0A
+    @SerializedName(%22engagement_rank%22)%0A    private double mEngagementRank;%0A    @SerializedName(%22weekly_completions%22)%0A    private int mWeeklyCompletions;%0A%0A
 %0A    /*-
@@ -1138,32 +1138,193 @@
 egoryId;%0A    %7D%0A%0A
+    public int getEngagementRank()%7B%0A        return (int)mEngagementRank;%0A    %7D%0A%0A    public int getWeeklyCompletions()%7B%0A        return mWeeklyCompletions;%0A    %7D%0A%0A
     @Override%0A  
@@ -1876,16 +1876,102 @@
 oryId);%0A
+        dest.writeDouble(mEngagementRank);%0A        dest.writeInt(mWeeklyCompletions);%0A
     %7D%0A%0A 
@@ -2416,16 +2416,16 @@
 der());%0A
-
         
@@ -2457,20 +2457,107 @@
 readLong();%0A
+        mEngagementRank = src.readDouble();%0A        mWeeklyCompletions =src.readInt();%0A
     %7D%0A%7D%0A

Add engagement data to UserGoal model