package in.th.llun.tent.model;

import in.th.llun.tent.remote.Tent;

import java.text.ParseException;
import java.util.Date;

import org.json.JSONObject;

import android.util.Log;

public class Topic extends JSONRemoteObject {

	public Topic(JSONObject raw) {
	  super(raw);
  }
	
	public String getId() {
		return mRaw.optString("id");
	}
	
	public String getTitle() {
		return mRaw.optString("title");
	}
	
	public String getExcerpt() {
		return mRaw.optString("excerpt");
	}
	
	public People getLastUpdater() {
		return new People(mRaw.optJSONObject("last_updater"));
	}
	
	public String getTopicId() {
		return getTopicable().optString("id");
	}
	
	public String getType() {
		return getTopicable().optString("type");
	}
	
	public String getUrl() {
		return getTopicable().optString("url");
	}
	
	public Date getUpdatedAt() {
		try {
			return Formatter.dateFromStringWithTimezone(mRaw.optString("updated_at"));
		} catch (ParseException e) {
			Log.e(Tent.LOG_TAG, "Can't parse date format", e);
			return null;
		}
	}

	public Date getCreatedAt() {
		try {
			return Formatter.dateFromStringWithTimezone(mRaw.optString("created_at"));
		} catch (ParseException e) {
			Log.e(Tent.LOG_TAG, "Can't parse date format", e);
			return null;
		}
	}
	
	public int getNumberOfAttachment() {
		return mRaw.optInt("attachments");
	}
	
	private JSONObject getTopicable() {
		return mRaw.optJSONObject("topicable");
	}

}

@@ -254,18 +254,17 @@
 raw) %7B%0A%09
-  
+%09
 super(ra
@@ -271,13 +271,11 @@
 w);%0A
-  
+%09
 %7D%0A
-%09
 %0A%09pu
@@ -322,34 +322,33 @@
 tring(%22id%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public String g
@@ -388,34 +388,33 @@
 ng(%22title%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public String g
@@ -462,26 +462,25 @@
 cerpt%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public Peop
@@ -557,26 +557,25 @@
 ater%22));%0A%09%7D%0A
-%09
 %0A
+
 %09public Stri
@@ -632,26 +632,25 @@
 g(%22id%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public Stri
@@ -706,26 +706,25 @@
 %22type%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public Stri
@@ -778,26 +778,25 @@
 (%22url%22);%0A%09%7D%0A
-%09
 %0A
+
 %09public Date
@@ -1232,18 +1232,17 @@
 %0A%09%09%7D%0A%09%7D%0A
-%09
 %0A
+
 %09public 
@@ -1311,17 +1311,16 @@
 s%22);%0A%09%7D%0A
-%09
 %0A%09privat

Format topic code.