/**
 * This file was auto-generated by the Titanium Module SDK helper for Android
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */
package ti.intercom.android;

import java.util.HashMap;
import java.util.Map;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;

import io.intercom.android.sdk.Intercom;
import io.intercom.android.sdk.identity.Registration;

@Kroll.module(name="Tiintercomandroid", id="ti.intercom.android")
public class TiintercomandroidModule extends KrollModule
{

	// Standard Debugging variables
	private static final String LCAT = "TiintercomandroidModule";
	private static final boolean DBG = TiConfig.LOGD;
	public static TiApplication theApp;
	public boolean initialized = false;

	// You can define constants with @Kroll.constant, for example:
	// @Kroll.constant public static final String EXTERNAL_NAME = value;

	public TiintercomandroidModule()
	{
		super();
	}

	@Kroll.onAppCreate
  public static void onAppCreate(TiApplication app) {
    Log.d(LCAT, "TiIntercom : onAppCreate");
    theApp = app;
  }

  @Kroll.method
  public void initialize(KrollDict props) {
    Log.d(LCAT, "TiIntercom : initialize()");
    if (props.containsKey("api_key") && props.containsKey("app_id")) {
      Intercom.initialize(theApp, props.getString("api_key"), props.getString("app_id"));
      initialized = true;
    } else {
      Log.d(LCAT, "Intercom : intialize() requies api_key and app_id to be set");
    }
  }

  @Kroll.method
  public void reset() {
    Intercom.client().reset();
    Log.d(LCAT, "Intercom : reset()");
  }

  @Kroll.method
  public void registerUnidentifiedUser() {
	Intercom.client().registerUnidentifiedUser();
    Log.d(LCAT, "Intercom : registerUnidentifiedUser();");
  }
  
  @Kroll.method
  public void registerUserWithUserID(String userid) {
    Intercom.client().registerIdentifiedUser(new Registration().withUserId(userid));
    Log.d(LCAT, "Intercom : registerUserWithUserID() : " + userid);
  }

  @Kroll.method
  public void registerUserWithEmail(String email) {
    Intercom.client().registerIdentifiedUser(new Registration().withEmail(email));
    Log.d(LCAT, "Intercom : registerUserWithEmail() : " + email);
  }

  @Kroll.method
  public void presentConversationList() {
    Intercom.client().displayConversationsList();
    Log.d(LCAT, "Intercom : presentConversationList()");
  }
  
  @Kroll.method
  public void presentMessageComposer() {
    Intercom.client().displayMessageComposer();
    Log.d(LCAT, "Intercom : presentMessageComposer()");
  }
  
  @Kroll.method
  public void logEventWithUserIDAndData(String event_name, String created_at, String user_id) {
	  Map eventData = new HashMap(); 
	  eventData.put("event_name", event_name); 
	  eventData.put("created_at", created_at);
	  eventData.put("user_id", user_id);
	  Intercom.client().logEvent(event_name, eventData);
	  Log.d(LCAT, "Intercom : logEventWithNameAndData()");
  }
  
  @Kroll.method
  public void logEventWithEmailAndData(String event_name, String created_at, String email) {
	  Map eventData = new HashMap(); 
	  eventData.put("event_name", event_name); 
	  eventData.put("created_at", created_at);
	  eventData.put("email", email);
	  Intercom.client().logEvent(event_name, eventData);
	  Log.d(LCAT, "Intercom : logEventWithEmailAndData()");
  }
  
  

}


@@ -3689,13 +3689,585 @@
  %7D%0A  %0A  
+@Kroll.method%0A  public void logEventWithNameAndData(String event_name, HashMap eventData) %7B%0A%09  Intercom.client().logEvent(event_name, eventData);%0A%09  Log.d(LCAT, %22Intercom : logEventWithNameAndData()%22);%0A  %7D%0A  %0A  @Kroll.method%0A  public void updateUserWithAttributes(HashMap userData) %7B%0A%09  Intercom.client().updateUser(userData);%0A%09  Log.d(LCAT, %22Intercom : updateUserWithAttributes()%22);%0A  %7D%0A  %0A  @Kroll.method%0A  public void setDeviceToken(String token, int ic_push_logo) %7B%0A%09  Intercom.client().setupGCM(token, ic_push_logo);%0A%09  Log.d(LCAT, %22Intercom : setDeviceToken()%22);%0A  %7D
 %0A%0A%7D%0A%0A

Added other useful functions: