package com.palmnest.service;

import java.io.Serializable;
import java.util.List;

import com.palmnest.model.lingling.LingLingDevice;

/**
 * Generic Manager that talks to GenericDao to CRUD POJOs.
 *
 * <p>
 * Extend this interface if you want typesafe (no casting necessary) managers
 * for your domain objects.
 *
 * @param <T>  a type variable
 * @param <PK> the primary key for that type
 * @author <a href="mailto:chasel.java@gmail.com">Chasel Li</a>
 */
public interface GenericManager<T, PK extends Serializable> {

	/**
	 * Generic method used to get all objects of a particular type. This is the
	 * same as lookup up all rows in a table.
	 *
	 * @return List of populated objects
	 */
	List<T> getAll();

	List<T> getAllDistinct();

	/**
	 * Generic method to get an object based on class and identifier. An
	 * ObjectRetrievalFailureException Runtime Exception is thrown if nothing is
	 * found.
	 *
	 * @param id the identifier (primary key) of the object to get
	 * @return a populated object
	 * @see org.springframework.orm.ObjectRetrievalFailureException
	 */
	T get(PK id);

	/**
	 * Checks for existence of an object of type T using the id arg.
	 *
	 * @param id the identifier (primary key) of the object to get
	 * @return - true if it exists, false if it doesn't
	 */
	boolean exists(PK id);

	/**
	 * Generic method to save an object - handles both update and insert.
	 *
	 * @param object the object to save
	 * @return the updated object
	 */
	T save(T object);

	/**
	 * Generic method to save an object
	 *
	 * @param object
	 * @return the updated object
	 */
	T saveModel(T object);

	/**
	 * Generic method to update an object
	 *
	 * @param object
	 * @return the updated object
	 */
	void updateModel(T object);

	/**
	 * Generic method to delete an object
	 *
	 * @param object the object to remove
	 */
	void remove(T object);

	/**
	 * Generic method to delete an object based on class and id
	 *
	 * @param id the identifier (primary key) of the object to remove
	 */
	void remove(PK id);

	/**
	 * Generic method to search for an object.
	 *
	 * @param searchTerm the search term
	 * @param clazz      type of class to search for.
	 * @return a list of matched objects
	 */
	@SuppressWarnings("rawtypes")
	List<T> search(String searchTerm, Class clazz);

	/**
	 * Generic method to regenerate full text index of the persistent class T
	 */
	void reindex();

	/**
	 * Generic method to regenerate full text index of all indexed classes
	 *
	 * @param async true to perform the reindexing asynchronously
	 */
	void reindexAll(boolean async);
}
