package com.uservoice.uservoicesdk.model;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.uservoice.uservoicesdk.rest.Callback;
import com.uservoice.uservoicesdk.rest.RestTaskCallback;

public class Forum extends BaseModel {
	private String name;
	private int numberOfVotesAllowed;
	private int numberOfOpenSuggestions;
	private List<Category> categories;
	
	public static void loadForum(int forumId, final Callback<Forum> callback) {
		doGet(apiPath("/forums/%d.json", forumId), new RestTaskCallback(callback) {
			@Override
			public void onComplete(JSONObject object) throws JSONException {
				callback.onModel(deserializeObject(object, "forum", Forum.class));
			}
		});
	}
	
	@Override
	public void load(JSONObject object) throws JSONException {
		super.load(object);
		name = getString(object, "name");
		JSONObject topic = object.getJSONArray("topics").getJSONObject(0);
		numberOfOpenSuggestions = topic.getInt("open_suggestions_count");
		numberOfVotesAllowed = topic.getInt("votes_allowed");
		categories = deserializeList(topic, "categories", Category.class);
	}
	
	public String getName() {
		return name;
	}
	
	public int getNumberOfOpenSuggestions() {
		return numberOfOpenSuggestions;
	}
	
	public int getNumberOfVotesAllowed() {
		return numberOfVotesAllowed;
	}
	
	public List<Category> getCategories() {
		return categories;
	}
}

@@ -36,16 +36,44 @@
 model;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -1141,16 +1141,100 @@
 class);%0A
+        if (categories == null)%0A            categories = new ArrayList%3CCategory%3E();%0A
 %09%7D%0A%09%0A%09pu

Make sure forum categories is not null