package com.tandbergtv.watchpoint.pmm.core;

import java.util.Collection;
import java.util.List;

import com.tandbergtv.metadatamanager.model.Asset;
import com.tandbergtv.watchpoint.pmm.entities.Planner;
import com.tandbergtv.watchpoint.pmm.entities.Title;
import com.tandbergtv.workflow.core.service.Service;

/**
 * Event handler interface for PMM.
 * 
 * @author Raj Prakash
 */
/* May be moved to individual message handlers themselves. */
public interface IPMMService extends Service {
	
	/**
	 * Handles "Asset Arrived" event.
	 * 
	 * @param filePath				path to the asset file
	 * @param sourceComponentName 	component which caused this event
	 * @param sourceEntityName   	name of the entity within the component which caused this event
	 * @param sourceId				id of the entity which caused this event 
	 * @return
	 */
	AssetMapInfo assetArrived(String filePath, String sourceComponentName,
			String sourceEntityName, String sourceId);
	
	/**
	 * Handles "ProgramList Arrived" event.
	 * 
	 * @param titles
	 * @throws PMMException		if there are multiple titles with the same key
	 */
	void programListArrived(Collection<Title> titles) throws PMMException;
	
	/**
	 * Handles "Planners Arrived" event.
	 * 
	 * @param planners
	 * @throws PMMException
	 */
	void plannersArrived(Collection<Planner> planners) throws PMMException;
	
	/**
	 * Handles "Metadata Arrived" event.
	 * 
	 * @param spec
	 * @param filePath
	 * @param createIfNotExist		flag to force create a title when no mapping title exist
	 * @param sourceComponentName 	component which caused this event
	 * @param sourceEntityName   	name of the entity within the component which caused this event
	 * @param sourceId				id of the entity which caused this event 
	 * @return						mapping information
	 * @throws PMMException 			
	 */
	MetadataMapInfo metadataArrived(String spec, String filePath, boolean createIfNotExist,
			String sourceComponentName, String sourceEntityName, String sourceId) throws PMMException;
	
	/**
	 * Finds the earliest upcoming planner that has this title (if one available) and
	 * updates asset received status (if one configured) for the given title.
	 *  
	 * @param title					the title for which the status is to be sent
	 * @param titleName				the name of the title for which the status has to be updated
	 * @param sourceComponentName 	component which caused this event
	 * @param sourceEntityName   	name of the entity within the component which caused this event
	 * @param sourceId				id of the entity which caused this event 
	 */
	void sendAssetReceivedStatus(Title title, String titleName,
			String sourceComponentName, String sourceEntityName, String sourceId);

	/**
	 * Finds the earliest upcoming planner that has this title (if one available) and
	 * updates metadata received status (if one configured) for the given title.
	 * 
	 * @param title					the title for which the status is to be sent
	 * @param sourceComponentName 	component which caused this event
	 * @param sourceEntityName   	name of the entity within the component which caused this event
	 * @param sourceId				id of the entity which caused this event 
	 */
	void sendMetadataReceivedStatus(Title title,
			String sourceComponentName, String sourceEntityName, String sourceId);
	
	/**
	 * Updates (in memory) the title status in the given title object.
	 */
	void updateTitleStatus(Title rootTitle);

	/**
	 * Files in unmapped files directory are mapped to the given rootAsset's descendant assets,
	 * if they are referred by those assets.
	 * 
	 * Uses the AssetsManager's current transaction.
	 * 
	 * @param rootAsset
	 * @return				list of assets that have been mapped
	 */
	public List<Asset> mapFiles(Asset rootAsset);

	/** 
	 * Sends Progress Status for the given title.
	 */
	public void sendStatus(Title title, String statusName, String statusValue,
			boolean success, String sourceComponentName, String sourceEntityName, String sourceId);
}
