/**********************************************************************************
 * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-3-1/podcasts-api/src/java/org/sakaiproject/api/app/podcasts/PodcastService.java $
 * $Id: PodcastService.java 14725 2006-09-15 16:01:17Z lance@indiana.edu $
 ***********************************************************************************
 *
 * Copyright (c) 2006 The Sakai Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at
 * 
 *      http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 *
 **********************************************************************************/

package org.sakaiproject.api.app.podcasts;

import java.util.Date;
import java.util.List;

import org.sakaiproject.content.api.ContentCollection;
import org.sakaiproject.content.api.ContentCollectionEdit;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResourceEdit;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.exception.IdInvalidException;
import org.sakaiproject.exception.IdLengthException;
import org.sakaiproject.exception.IdUniquenessException;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.IdUsedException;
import org.sakaiproject.exception.InUseException;
import org.sakaiproject.exception.InconsistentException;
import org.sakaiproject.exception.OverQuotaException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.exception.ServerOverloadException;
import org.sakaiproject.exception.TypeException;
import org.sakaiproject.tool.api.ToolManager;

// import org.sakaiproject.entity.api.EntityProducer;

public interface PodcastService // extends EntityProducer
{
	/** This string can be used to find the service in the service manager. */
	public static final String COLLECTION_PODCASTS = "Podcasts";
	
	/** This string can be used as an alternate method to finding the podcasts folder */
	public static final String COLLECTION_PODCASTS_ALT = "podcasts";
	
	/** This string used as part of URL for podcast feed **/
	public static final String COLLECTION_PODCASTS_FEED = "podcastsFeed";
	
	/** This string used for Title of the podcast collection **/
	public static final String COLLECTION_PODCASTS_TITLE = "Podcasts";
	
	/** This string gives description for podcasts folder **/
	public static final String COLLECTION_PODCASTS_DESCRIPTION = "Common Folder for All Site Podcasts";

	/** This string gives the Service name (class w/ package prefix) for podcast service **/
	public static final String PODCASTS_SERVICE_NAME = "org.sakaiproject.api.app.syllabus.PodcastService";

	/** This string is the name of the property used when displaying and sorting the podcasts **/
	public static final String DISPLAY_DATE = "displayDate";
	
	/** This string is the name of the property for the title of a podcast in the feed **/
	public static final String DISPLAY_TITLE = "displayTitle";
	
	/** This string gives the update function (permission) string for checking permissions **/
	public static final String UPDATE_PERMISSIONS = "site.upd";

	/**
	 * Determines if podcast folder is part of Resources of site.
	 * If not, creates it.
	 * 
	 * @return true if folder exists/created, false otherwise.
	 */
	public boolean checkPodcastFolder () throws InUseException, PermissionException;

	/**
	 * Will check if any podcasts were added in Resources and do not have their DISPLAY_DATE property set.
	 * 
	 * @param resourcesList The List of podcasts to check
	 * 
	 * @return List of updated podcasts
	 */
	public List checkDISPLAY_DATE(List resourcesList);

	/**
	 * Determines if there are actual podcasts in the folder
	 * 
	 * @return true if there are actual podcasts, false otherwise
	 */
	public boolean checkForActualPodcasts() throws PermissionException;

	/**
	 * Used to inject the ContentHostingService
	 * 
	 * @param chs The application's ContentHostingService
	 */
	public void setContentHostingService(ContentHostingService chs);
	
	/**
	 * Used to inject the ToolManager
	 * 
	 * @param tm The application's ToolManager
	 */
	public void setToolManager(ToolManager tm);
	
	/**
	 * Returns a list of the podcasts stored in site/podcasts folder
	 * 
	 * @return List of podcasts
	 */
	public List getPodcasts()throws PermissionException, InUseException, IdInvalidException, 
					InconsistentException, IdUsedException;
	
	/**
	 * Returns a list of the podcasts stored in site/podcasts folder
	 * 
	 * @param siteID Passed in by the podfeed server
	 * 
	 * @return List of podcasts
	 * 
	 * @throws PermissionException
	 * @throws InUseException
	 * @throws IdInvalidException
	 * @throws InconsistentException
	 * @throws IdUsedException
	 */
	public List getPodcasts(String siteID)throws PermissionException, InUseException, IdInvalidException, 
					InconsistentException, IdUsedException;
	
	/**
	 * Returns SiteId for the site this tool is a part of
	 * 
	 * @return String of the site id
	 */
	public String getSiteId();
	
	/**
	 * Returns UserId for the current user
	 * 
	 * @return String of the user ID
	 */
	public String getUserId();
	
	/**
	 * Returns the full URL of the file from ContentHostingService
	 * 
	 * @param resourceId The ID for the file whose URL is wanted
	 * 
	 * @return String The full URL for the file
	 */
	public String getPodcastFileURL(String resourceId) throws PermissionException, IdUnusedException;

	/**
	 * Returns an editable resource if ID exists.
	 * 
	 * @param String
	 *            	The resourceId of the resource to get
	 *            
	 * @return ContentResourceEdit 
	 * 				If found, null otherwise
	 */
	public ContentResourceEdit getAResource(String resourceId) throws PermissionException, IdUnusedException;

	/**
	 * Sets the DISPLAY_DATE property of a podcast to CREATION_DATE
	 * 
	 * @param rp The ResourceProperties of the podcast to set 
	 */
	public void setDISPLAY_DATE(ResourceProperties rp);

	/**
	 * Does the actual adding of podcast to Resources
	 * 
	 * @param title User specified title for the podcast
	 * @param displayDate Date when podcast will be available for viewing
	 * @param description User specified description for the podcast
	 * @param body The actual contents of the podcast
	 * @param filename The filename of the podcast being saved
	 */
	public void addPodcast(String title, Date displayDate, String description, byte[] body, 
			               String filename, String contentType) throws OverQuotaException, ServerOverloadException, InconsistentException,
			               IdInvalidException, IdLengthException, PermissionException, IdUniquenessException;
	
	/**
	 * Removes a podcast from site/podcasts folder
	 * 
	 * @param resourceId resourceId of the podcast to be deleted
	 */
	public void removePodcast(String resourceId)
		throws IdUnusedException, InUseException, TypeException, PermissionException; 
	
	/**
	 * Returns an editable resource if ID exists.
	 * 
	 * @return ContentResourceEdit object if ID valid, null otherwise
	 */
	public void revisePodcast(String resourceId, String title, Date date, String description, byte[] body, 
            String filename) throws PermissionException, InUseException, OverQuotaException, ServerOverloadException;
	
	/**
	 * Determines if user can modify the site. Used by feed.
	 * 
	 * @return boolean true if user can modify, false otherwise
	 */
	public boolean canUpdateSite(String siteId);
	
	/**
	 * Determines if user can modify the site. Used within the tool.
	 * 
	 * @return boolean true if user can modify, false otherwise
	 */
	public boolean canUpdateSite();
	
	/**
	 * Returns the ContentCollection that contains the podcasts.
	 * 
	 * @param siteId The site id to pull the correct collection
	 * 
	 * @return ContentCollection
	 */
	public ContentCollection getContentCollection(String siteId) throws IdUnusedException, PermissionException;
	
	/**
	 * Returns the ContentCollection that contains the podcasts.
	 * 
	 * @param siteId The site id to pull the correct collection
	 * 
	 * @return ContentCollection
	 */
	public ContentCollectionEdit getContentCollectionEditable(String siteId) throws IdUnusedException, PermissionException, InUseException;
	
	/**
	 * Changes whether the podcast folder is public/private
	 * 
	 * @param option int that sets the public/private option
	 */
	public void reviseOptions(boolean option);

	/**
	 * Only add podcast resources whose DISPLAY_DATE is today or earlier
	 * 
	 * @param resourcesList List of podcasts
	 * 
	 * @return List of podcasts whose DISPLAY_DATE is today or before
	 */
	public List filterPodcasts(List resourcesList);

	/**
	 * Gets whether the podcast folder is Publicly viewable or not.
	 * 
	 * @return int 0 = Public 1 = Site 
	 */
	public int getOptions();
	
	/**
	 * Commit the changes made to the ContentCollection.
	 * 
	 * @param contentCollectionEdit The ContentCollection object that needs to be commited.
	 */
	public void commitContentCollection(ContentCollectionEdit contentCollectionEdit);
	
	/**
	 * Cancels attempt at changing this collection (releases the lock)
	 * 
	 * @param cce
	 *            The ContentCollectionEdit that is not to be changed
	 */
	public void cancelContentCollection(ContentCollectionEdit cce);

	/**
	 * Returns podcast folder id using either 'podcasts' or 'Podcasts'. If it
	 * does not exist in either form, will create it.
	 * 
	 * @param siteId
	 *            The site to search
	 * @return String containing the complete id for the podcast folder
	 * 
	 * @throws PermissionException
	 */
	public String retrievePodcastFolderId(String siteId)
			throws PermissionException; 

	/**
	 * Returns whether site is Public (true) or Site (false)
	 * @param siteId
	 * @return
	 */
	public boolean isPublic(String siteId);
	
	/**
	 * Takes the date String passed in and converts it to a Date object
	 * using GMT time
	 * 
	 * @param date
	 * 			A long value representing the date to be converted`
	 * 
	 * @return
	 * 			Date object created
	 */
	public Date getGMTdate(long date);

	/**
	 * Determines if authenticated user has 'read' access to podcast collection folder
	 * 
	 * @param id
	 * 			The id for the podcast collection folder
	 * 
	 * @return
	 * 		TRUE - has read access, FALSE - does not
	 */
	public boolean allowAccess(String id);

}