package com.growthbeat.model;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jackson.type.TypeReference;

import com.growthbeat.Context;

public class Intent extends Model {

	private String id;
	private String applicationId;
	private String name;
	private String description;
	private Type type;
	private Date created;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getApplicationId() {
		return applicationId;
	}

	public void setApplicationId(String applicationId) {
		this.applicationId = applicationId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public static int findCountByApplicationId(String applicationId, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("applicationId", applicationId);
		return get(context, "1/intents/count", params, Integer.class);
	}

	public static Intent findById(String id, Context context) {
		return get(context, String.format("1/intents/%s", id), new HashMap<String, Object>(), Intent.class);
	}

	public static List<Intent> findByApplicationId(String applicationId, Order order, Integer page, Integer limit, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("applicationId", applicationId);
		if (order != null)
			params.put("order", order);
		if (page != null)
			params.put("page", page);
		if (limit != null)
			params.put("limit", limit);
		return get(context, "1/intents", new HashMap<String, Object>(), new TypeReference<List<Intent>>() {
		});
	}

	public static Intent create(String applicationId, String name, String description, Type type, Map<String, String> parameters,
			Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("applicationId", applicationId);
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		params.put("parameters", parameters);
		return post(context, "1/intents", params, Intent.class);
	}

	public static Intent create(String applicationId, String name, String description, Type type, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("applicationId", applicationId);
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		return post(context, "1/intents", params, Intent.class);
	}

	public static Intent create(String applicationId, String name, String description, Type type, String url, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("applicationId", applicationId);
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		params.put("url", url);
		return post(context, "1/intents", params, Intent.class);
	}

	public static Intent update(String id, String name, String description, Type type, Map<String, String> parameters, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		params.put("parameters", parameters);
		return put(context, String.format("1/intents/%s", id), params, Intent.class);
	}

	public static Intent update(String id, String name, String description, Type type, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		return put(context, String.format("1/intents/%s", id), params, Intent.class);
	}

	public static Intent update(String id, String name, String description, Type type, String url, Context context) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		params.put("description", description);
		params.put("type", type);
		params.put("url", url);
		return put(context, String.format("1/intents/%s", id), params, Intent.class);
	}

	public static void delete(String id, Context context) {
		delete(context, String.format("1/intents/%s", id), new HashMap<String, Object>(), Void.class);
	}

	public enum Type {
		custom, noop, url
	}

}

@@ -130,20 +130,73 @@
 ort 
-org.codehaus
+com.fasterxml.jackson.annotation.JsonFormat;%0Aimport com.fasterxml
 .jac
@@ -200,16 +200,21 @@
 jackson.
+core.
 type.Typ
@@ -225,17 +225,16 @@
 erence;%0A
-%0A
 import c
@@ -255,16 +255,59 @@
 Context;
+%0Aimport com.growthbeat.constants.Constants;
 %0A%0Apublic
@@ -459,16 +459,39 @@
 e type;%0A
+%09private Date updated;%0A
 %09private
@@ -1108,32 +1108,336 @@
 ype = type;%0A%09%7D%0A%0A
+%09@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Constants.ISO_8601_DATETIME_FORMAT)%0A%09public Date getUpdated() %7B%0A%09%09return updated;%0A%09%7D%0A%0A%09public void setUpdated(Date updated) %7B%0A%09%09this.updated = updated;%0A%09%7D%0A%0A%09@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Constants.ISO_8601_DATETIME_FORMAT)%0A
 %09public Date get
@@ -2401,37 +2401,14 @@
 s%22, 
-new HashMap%3CString, Object%3E()
+params
 , ne

Add column 'updated' to table 'intent'