package com.setiawanpaiman.sunnyreader.data.model;

import android.support.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

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

public class Comment {

    @SerializedName("id")
    private long mId;

    @SerializedName("time")
    private long mTimestamp;

    @SerializedName("by")
    private String mAuthor;

    @SerializedName("text")
    private String mText;

    @SerializedName("parent")
    private long mParentId;

    @SerializedName("kids")
    private List<Long> mCommentIds;

    @SerializedName("deleted")
    private boolean mDeleted;

    private int mDepth;

    protected Comment(Builder builder) {
        mId = builder.mId;
        mTimestamp = builder.mTimestamp;
        mAuthor = builder.mAuthor;
        mText = builder.mText;
        mParentId = builder.mParentId;
        mCommentIds = builder.mCommentIds;
        mDeleted = builder.mDeleted;
    }

    public long getId() {
        return mId;
    }

    public long getTimestamp() {
        return mTimestamp;
    }

    public String getAuthor() {
        return mAuthor;
    }

    public long getParentId() {
        return mParentId;
    }

    @NonNull
    public List<Long> getCommentIds() {
        // defensive copy
        if (mCommentIds == null) return new ArrayList<>();
        else return new ArrayList<>(mCommentIds);
    }

    public String getText() {
        return mText;
    }

    public boolean isDeleted() {
        return mDeleted;
    }

    public int getDepth() {
        return mDepth;
    }

    public void setDepth(int depth) {
        mDepth = depth;
    }

    public static Builder newBuilder(long id) {
        return new Builder(id);
    }

    public static class Builder {
        private long mId;
        private long mTimestamp;
        private String mAuthor;
        private long mParentId;
        private List<Long> mCommentIds;
        private String mText;
        private boolean mDeleted;

        public Builder(long id) {
            mId = id;
            mCommentIds = new ArrayList<>();
        }

        public Builder setTimestamp(long timestamp) {
            mTimestamp = timestamp;
            return this;
        }

        public Builder setAuthor(String author) {
            mAuthor = author;
            return this;
        }

        public Builder setParentId(long parentId) {
            mParentId = parentId;
            return this;
        }

        public Builder setCommentIds(List<Long> commentIds) {
            mCommentIds.clear();
            if (commentIds != null) mCommentIds.addAll(commentIds);
            return this;
        }

        public Builder setText(String text) {
            mText = text;
            return this;
        }

        public Builder setDeleted(boolean deleted) {
            mDeleted = deleted;
            return this;
        }

        public Comment build() {
            return new Comment(this);
        }
    }
}

@@ -41,24 +41,80 @@
 ata.model;%0A%0A
+import android.os.Parcel;%0Aimport android.os.Parcelable;%0A
 import andro
@@ -144,16 +144,16 @@
 onNull;%0A
-
 %0Aimport 
@@ -270,17 +270,317 @@
 Comment 
-%7B
+implements Parcelable %7B%0A%0A    public static final Creator%3CComment%3E CREATOR = new Creator%3CComment%3E() %7B%0A        @Override%0A        public Comment createFromParcel(Parcel source) %7Breturn new Comment(source);%7D%0A%0A        @Override%0A        public Comment%5B%5D newArray(int size) %7Breturn new Comment%5Bsize%5D;%7D%0A    %7D;
 %0A%0A    @S
@@ -1250,32 +1250,32 @@
 er.mCommentIds;%0A
-
         mDeleted
@@ -1294,32 +1294,932 @@
 Deleted;%0A    %7D%0A%0A
+    protected Comment(Parcel in) %7B%0A        this.mId = in.readLong();%0A        this.mTimestamp = in.readLong();%0A        this.mAuthor = in.readString();%0A        this.mText = in.readString();%0A        this.mParentId = in.readLong();%0A        this.mCommentIds = new ArrayList%3CLong%3E();%0A        in.readList(this.mCommentIds, Long.class.getClassLoader());%0A        this.mDeleted = in.readByte() != 0;%0A        this.mDepth = in.readInt();%0A    %7D%0A%0A    @Override%0A    public int describeContents() %7B return 0; %7D%0A%0A    @Override%0A    public void writeToParcel(Parcel dest, int flags) %7B%0A        dest.writeLong(this.mId);%0A        dest.writeLong(this.mTimestamp);%0A        dest.writeString(this.mAuthor);%0A        dest.writeString(this.mText);%0A        dest.writeLong(this.mParentId);%0A        dest.writeList(this.mCommentIds);%0A        dest.writeByte(mDeleted ? (byte) 1 : (byte) 0);%0A        dest.writeInt(this.mDepth);%0A    %7D%0A%0A
     public long 

Implement Parcelable in Comment