package com.tandbergtv.metadatamanager;

import java.util.List;

import com.tandbergtv.metadatamanager.exception.MetadataException;
import com.tandbergtv.metadatamanager.exception.SearchException;
import com.tandbergtv.metadatamanager.model.Asset;
import com.tandbergtv.metadatamanager.model.RootAssetRevision;
import com.tandbergtv.metadatamanager.specimpl.ttv.TTVId;

public interface ITTVDataModelHandler {

	/**
	 * @param asset
	 *            This is the Asset (Group/Item) as per the TTV Spec.
	 * @param saveAsDraft
	 * 			  indicates whether a draft version should be created for this update
	 * @return merged asset
	 * 
	 * Scenarios - - The asset may contain relation(s) to an existing
	 * group/item.
	 */
	Asset saveAsset(Asset asset, boolean saveAsDraft) throws MetadataException;
	
	
	/**
	 * Same as {@link #saveAsset(Asset)))}, but with extra information related to Revision Tracking
	 * @param asset
	 * @param revisionSource
	 * @param revisionComment
	 * @param externalRevision
	 * @param createRevision
	 * 			  indicates whether a revision tracking has to be done for this update
	 * @return
	 * @throws MetadataException
	 */
	Asset saveAsset(Asset asset, String revisionSource, String revisionComment, String externalRevision, boolean createRevision) throws MetadataException;
	/**
	 * @param id
	 *            The id which uniquely identifies this asset and is known to
	 *            the application making this call. Would the id need to be
	 *            converted to TTV Spec Identifier or any other field?
	 * 
	 * Scenarios: - Single entry for the asset with that id is found. - Search
	 * results in multiple entries (could the versions be same?) for the same
	 * asset. - Multiple assets with the same id found. Is this even possible? -
	 * Asset with that id is not found. - That specific version not found.
	 * 
	 * Search for the asset with the given id and version.
	 * 
	 * @param id
	 * @return The latest version of the Asset.
	 */
	Asset getAsset(TTVId id) throws SearchException;
	
	/**
	 * Same as {@link #getAsset(TTVId)}, but return an Asset for a specific revision
	 * @param id
	 * @param revision In the format of ExternalRevision.InternalRevision, e.g. 1.5
	 * @return The latest version of the Asset if the version is null.
	 * @throws SearchException
	 */
	Asset getAsset(TTVId id, String revision) throws SearchException;
	
	/**
	 * 
	 * @param id
	 * @return a list of revisions for a given TTIVID, with the order of oldest to latest
	 * @throws SearchException
	 */
	List<RootAssetRevision> getRevisions(TTVId id) throws SearchException;

	/**
	 * All references are removed.
	 * 
	 * Should this be in sync with CMS which holds the content for this asset?
	 * 
	 * @param Id
	 *            TTV Asset Id
	 * 
	 * Scenarios: - Asset with that Id not found. - Asset with Id found. - Asset
	 * is an Item with no relations. - Asset is part of one group - update the
	 * group containing this asset. - Asset is part of multiple groups - update
	 * all groups containing this asset. - Asset has a one-one relation with
	 * another asset - update the other asset's relations.
	 */
	void delete(Asset asset) throws SearchException;	
}
