package com.appideas.base;

import java.util.HashMap;

/**
 * The APPideas Object Template<br/>
 *
 * Custom classes need to implement this as a minimal template for a data object<p/>
 *
 * The constructor should also require an ID as input
 *
 * @author		costmo
 * @version		20111213
 * @since		20111213
 */

public interface AiOT
{
	/**
	 * Check the values of member variables.<p/>
	 *
	 * Return "ok" if data passes, an error otherwise
	 *
	 * @since		20111213
	 * @return		String
	 * @param		isNew			true if this is an addition, false otherwise
	 */
	public abstract String checkMemberVars( boolean isNew );

	/**
	 * Populate all members from input such as a form<p/>
	 *
	 * Return true unless a problem is detected
	 *
	 * @since		20111213
	 * @return		boolean
	 * @param		input			Key/value pairs
	 */
	public abstract boolean populateMemberVars( HashMap<String,String>  input );

	/**
	 * Perform initial population of the instantiated object members from its data source.<p/>
	 *
	 * This should not be called directly, but only from the class constructor
	 *
	 * @since		20111213
	 */
	public abstract void assignMemberVars();

	/**
	 * Saves a new object's member variable values to the object's data source.<p/>
	 *
	 * Assumes that input has already been checked.<p/>
	 *
	 * Return the new object's ID, or 0 if there was a problem.
	 *
	 * @since		20111213
	 * @return		int
	 */
	public abstract int add();

	/**
	 * Saves the object's member variable values to the object's data source.<p/>
	 *
	 * Assumes that input has already been checked.<p/>
	 *
	 * Return the object's ID, or 0 if there was a problem.
	 *
	 * @since		20111213
	 * @return		int
	 */
	public abstract int save();

	/**
	 * Removes the object form the data source.<p/>
	 *
	 * The default for most objects should be to deactivate and hide from view rather than delete
	 *
	 * Return true on success, false otherwise
	 *
	 * @since		20111213
	 * @return		boolean
	 * param			delete				true if the item should be deleted, false if it should be deactivated
	 */
	public abstract boolean remove( boolean delete );

	/**
	 * Sets the object's active flag.<p/>
	 *
	 * Return true unless input is something other than 1 or 0
	 *
	 * @since		20111213
	 * @return		boolean
	 * @param		newValue				The value to set (1 or 0)
	 */
	public abstract boolean setActive( int newValue );

}
