package com.kickstarter.models;

import android.os.Parcel;
import android.os.Parcelable;

import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;

@ParcelablePlease
public class Category implements Parcelable {
  Integer id = null;
  String name = null;
  Integer parentId = null;

  public Integer id() {
    return id;
  }

  public String name() {
    return name;
  }

  public Integer parentId() {
    return parentId;
  }

  // TODO: Should be able to grab a Category rather than dealing with Integers. That would require loading all the
  // categories (probably on start-up). There is a bunch of work to do on categories, probably best to tackle it all
  // at once.
  public Integer rootId() {
    return isRootValue() ? id() : parentId();
  }

  public boolean isRootValue() {
    return parentId() == null || parentId() == 0;
  }

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

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    CategoryParcelablePlease.writeToParcel(this, dest, flags);
  }

  public static final Creator<Category> CREATOR = new Creator<Category>() {
    public Category createFromParcel(Parcel source) {
      Category target = new Category();
      CategoryParcelablePlease.readFromParcel(target, source);
      return target;
    }

    public Category[] newArray(int size) {
      return new Category[size];
    }
  };
}

@@ -289,16 +289,69 @@
  = null;
+%0A  Integer position = null;%0A  Category parent = null;
 %0A%0A  publ
@@ -491,16 +491,72 @@
 d;%0A  %7D%0A%0A
+  public Integer position() %7B%0A    return position;%0A  %7D%0A%0A
   // TOD
@@ -838,21 +838,16 @@
 n isRoot
-Value
 () ? id(
@@ -859,32 +859,85 @@
 arentId();%0A  %7D%0A%0A
+  public Category parent() %7B%0A    return parent;%0A  %7D%0A%0A
   public boolean
@@ -947,13 +947,8 @@
 Root
-Value
 () %7B
@@ -995,32 +995,392 @@
 Id() == 0;%0A  %7D%0A%0A
+  public int discoveryFilterCompareTo(final Category category) %7B%0A    if (isRoot()) %7B%0A      return name.compareTo(category.root().name());%0A    %7D else if (category.isRoot()) %7B%0A      return root().name().compareTo(category.name());%0A    %7D%0A%0A    return name.compareTo(category.name());%0A  %7D%0A%0A  public Category root() %7B%0A    return parent == null ? this : parent;%0A  %7D%0A%0A
   @Override%0A  pu

Add root category, sort functions