/**
 * ITemplateLoaderService.java
 * Created Jul 6, 2007
 * Copyright (c) Tandberg Television 2007
 */
package com.tandbergtv.workflow.driver.service;

import java.io.Serializable;
import java.util.List;

import com.tandbergtv.workflow.core.Selector;
import com.tandbergtv.workflow.core.WorkflowTemplate;
import com.tandbergtv.workflow.core.service.Service;
import com.tandbergtv.workflow.driver.DriverException;

/**
 * Loads templates
 * 
 * @author Sahil Verma
 */
public interface ITemplateLoaderService extends Service {

	/**
	 * Retrieves, without removing, the list of templates. If there are license restrictions,
	 * only those templates that are licensed are returned.
	 * 
	 * @return
	 */
	List<WorkflowTemplate> getAllTemplates();

	/**
	 * Retrieves, without removing, the list of latest versions of templates. If there are license 
	 * restrictions, only those templates that are licensed are returned.
	 * 
	 * @return
	 */
	List<WorkflowTemplate> getLatestTemplates();

	/**
	 * Returns a list of previous verions of the specified template
	 * 
	 * @param template
	 * @return the templates excluding the example
	 */
	List<WorkflowTemplate> getPreviousVersions(WorkflowTemplate template);

	/**
	 * Retrieves the list of names of the latest templates. If there are license 
	 * restrictions, the names of only those templates that are licensed are returned.
	 * 
	 * @return the template names
	 */
	List<String> getAllTemplateNames();

	/**
	 * Retrieves a workflow template using the specified key
	 * 
	 * @param id
	 * @return
	 * @throws DriverException if there is no template with the specified key
	 */
	WorkflowTemplate getTemplate(Serializable id) throws DriverException;

	/**
	 * Gets the latest workflow template by full name, where latest is defined as a template with
	 * the highest version number
	 * 
	 * @param name the unique full name
	 * @return the matching template
	 */
	WorkflowTemplate getTemplateByFullName(String name);

	/**
	 * Gets the latest workflow template by name, where latest is defined as a template with
	 * the highest version number
	 * 
	 * @param name the unique name
	 * @return the matching template
	 */
	WorkflowTemplate getTemplateByName(String name);

	/**
	 * Returns the template mapped to the specified selector
	 * 
	 * @param selectorKey
	 * @return
	 */
	WorkflowTemplate getTemplateBySelectorKey(String selectorKey);

	/**
	 * Creates the specified template. Note that any selectors mapped to a previous version are
	 * automatically transferred to the new one.
	 * 
	 * @param template
	 * @throws DriverException if the number of licensed templates has been exceeded, if the 
	 * version of the template is not the largest
	 */
	void save(WorkflowTemplate template) throws DriverException;

	/**
	 * Updates the specified template
	 * 
	 * @param template
	 * @throws DriverException
	 */
	void update(WorkflowTemplate template) throws DriverException;

	/**
	 * Deletes the specified template
	 * 
	 * @param template
	 */
	void delete(WorkflowTemplate template) throws DriverException;

	/**
	 * Adds the selector to the template with the specified id
	 * 
	 * @param id the template id
	 * @param selector the selector
	 */
	void addSelector(Serializable id, Selector selector) throws DriverException;

	/**
	 * Removes the selector
	 * 
	 * @param id
	 * @param selector
	 */
	void removeSelector(Serializable id, Selector selector) throws DriverException;
}
