/**
 * Perform click/tap actions on behalf of the Posts UI
 */
package com.sharefaith.churchapp.views.actions;

import java.util.Hashtable;

import com.codename1.ui.Container;
import com.sharefaith.churchapp.SFUtil;

public class PostsAction
{
	public Container callerContainer;
	public Hashtable<String,Object> selectedData;
	
	/**
	 * Class constructor. Provide the needed input for handling taps to create the instance
	 * 
	 * @since 20140312
	 * @author costmo
	 * @param		callerContainer		The container making this request in case we need to make it do anything
	 * @param		selectedData		The data element that was selected. It should probably be a Hashtable
	 */
	public PostsAction( Container callerContainer, Object selectedData )
	{
		this.selectedData = (Hashtable<String,Object>) selectedData;
		this.callerContainer = callerContainer;
	}
	
	/**
	 * Perform the action
	 * 
	 * @since 20140312
	 * @author costmo
	 */
	public void perform()
	{
		// catch conditions for which we should not act
		// 1. empty hashtable, 2. no 'id' key, 3. no 'messageCount' key, 4. id <= 0 (there are no defined series'), 5. messageCount <= 0 (there are no messages for this series)
		if( this.selectedData.isEmpty() || !this.selectedData.containsKey( "id" ) || 1 > Integer.valueOf( (Integer)this.selectedData.get( "id" ) ) )
		{
			return;
		}
		
		// If we're here, we should do something
		SFUtil.p( "perform action" );
		SFUtil.p( this.selectedData.toString() );
	}
}
