package org.tndata.android.compass.model;

import android.os.Parcel;

import com.google.gson.annotations.SerializedName;

import org.tndata.android.compass.parser.ParserModels;

import java.util.ArrayList;
import java.util.List;


/**
 * Model class for user behaviors.
 *
 * @author Ismael Alonso
 * @version 1.0.0
 */
public class UserBehavior extends UserContent implements ParserModels.ResultSet{
    public static final String TYPE = "userbehavior";


    //Values retrieved from the API
    @SerializedName("behavior")
    private TDCBehavior mBehavior;

    //Values set during post-processing
    private List<UserGoal> userGoals = new ArrayList<>();
    private List<UserAction> userActions = new ArrayList<>();


    public UserBehavior(TDCBehavior behavior){
        this.mBehavior = behavior;
    }


    /*---------*
     * SETTERS *
     *---------*/

    public void setGoals(List<UserGoal> goals) {
        this.userGoals = goals;
    }

    public void setActions(List<UserAction> actions){
        this.userActions = actions;
    }


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

    public TDCBehavior getBehavior(){
        return mBehavior;
    }

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

    public String getTitle(){
        return mBehavior.getTitle();
    }

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

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

    public String getIconUrl(){
        return mBehavior.getIconUrl();
    }

    public List<UserGoal> getGoals(){
        return userGoals;
    }

    public List<UserAction> getActions(){
        return userActions;
    }

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

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

    @Override
    public void init(){
        if (userGoals == null){
            userGoals = new ArrayList<>();
        }
        if (userActions == null){
            userActions = new ArrayList<>();
        }
    }

    public void addGoal(UserGoal goal){
        if (!userGoals.contains(goal)){
            userGoals.add(goal);
        }
    }

    public void removeGoal(UserGoal goal){
        if (userGoals.contains(goal)){
            userGoals.remove(goal);
        }
    }

    public void addAction(UserAction action){
        if (!userActions.contains(action)){
            userActions.add(action);
        }
    }

    public void removeAction(UserAction action){
        if (userActions.contains(action)){
            userActions.remove(action);
        }
    }

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

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

    @Override
    public void writeToParcel(Parcel dest, int flags){
        super.addToParcel(dest, flags);
        dest.writeParcelable(mBehavior, flags);
    }

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

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

    private UserBehavior(Parcel src){
        super(src);
        mBehavior = src.readParcelable(TDCBehavior.class.getClassLoader());
    }
}

@@ -175,60 +175,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 %0A/**
@@ -506,498 +506,8 @@
 r;%0A%0A
-    //Values set during post-processing%0A    private List%3CUserGoal%3E userGoals = new ArrayList%3C%3E();%0A    private List%3CUserAction%3E userActions = new ArrayList%3C%3E();%0A%0A%0A    public UserBehavior(TDCBehavior behavior)%7B%0A        this.mBehavior = behavior;%0A    %7D%0A%0A%0A    /*---------*%0A     * SETTERS *%0A     *---------*/%0A%0A    public void setGoals(List%3CUserGoal%3E goals) %7B%0A        this.userGoals = goals;%0A    %7D%0A%0A    public void setActions(List%3CUserAction%3E actions)%7B%0A        this.userActions = actions;%0A    %7D%0A%0A
 %0A   
@@ -1050,156 +1050,8 @@
  %7D%0A%0A
-    public List%3CUserGoal%3E getGoals()%7B%0A        return userGoals;%0A    %7D%0A%0A    public List%3CUserAction%3E getActions()%7B%0A        return userActions;%0A    %7D%0A%0A
     
@@ -1215,739 +1215,8 @@
 ()%7B%0A
-        if (userGoals == null)%7B%0A            userGoals = new ArrayList%3C%3E();%0A        %7D%0A        if (userActions == null)%7B%0A            userActions = new ArrayList%3C%3E();%0A        %7D%0A    %7D%0A%0A    public void addGoal(UserGoal goal)%7B%0A        if (!userGoals.contains(goal))%7B%0A            userGoals.add(goal);%0A        %7D%0A    %7D%0A%0A    public void removeGoal(UserGoal goal)%7B%0A        if (userGoals.contains(goal))%7B%0A            userGoals.remove(goal);%0A        %7D%0A    %7D%0A%0A    public void addAction(UserAction action)%7B%0A        if (!userActions.contains(action))%7B%0A            userActions.add(action);%0A        %7D%0A    %7D%0A%0A    public void removeAction(UserAction action)%7B%0A        if (userActions.contains(action))%7B%0A            userActions.remove(action);%0A        %7D
 %0A   
@@ -1510,11 +1510,13 @@
 per.
-add
+write
 ToPa

Clean up UserBehavior model