/**
 * IScheduleSearchService.java
 * Created Jun 8, 2008
 * Copyright (c) TANDBERG Television 2007-2008
 */
package com.tandbergtv.watchpoint.pmm.schedule.search;

import java.util.Collection;
import java.util.Date;

import com.tandbergtv.watchpoint.pmm.entities.DistributionSchedule;
import com.tandbergtv.watchpoint.pmm.entities.Planner;
import com.tandbergtv.watchpoint.pmm.entities.Schedule;
import com.tandbergtv.watchpoint.pmm.entities.ScheduleStatus;
import com.tandbergtv.workflow.core.service.Service;
import com.tandbergtv.workflow.util.SearchCriteria;

/**
 * Schedule search interface
 * 
 * @author Sahil Verma
 */
public interface IScheduleSearchService extends Service {
	
	/**
	 * Returns the number of schedules that match the given criteria
	 * 
	 * @param criteria
	 * @return
	 */
	int count(SearchCriteria criteria);

	/**
	 * Searches by arbitrary criteria. The start index for result set and max
	 * result count will be ignored when fetching the results.
	 * 
	 * @param criteria
	 * @return
	 */
	<T extends Schedule> Collection<T> search(SearchCriteria criteria);

	/**
	 * Returns planners that fall within the specified date range, filtered by the partner
	 * 
	 * @param partner
	 * @param start
	 * @param end
	 * @return
	 */
	Collection<Planner> getPlannersByDateRange(Long partner, Date start, Date end);
	
	/**
	 * Returns planners for the specified date. This should return only one result in the
	 * normal case.
	 * 
	 * @param partnerId
	 * @param date
	 * @return
	 */
	Collection<Planner> getPlannersByDate(Long partnerId, Date date);
	
	/**
	 * Returns pitch schedules that fall within the specified date range, filtered by the context
	 * 
	 * @param contextId
	 * @param start
	 * @param end
	 * @return
	 */
	Collection<DistributionSchedule> getPitchSchedulesByDateRange(Long contextId, Date start, Date end);
	
	/**
	 * Returns pitch schedules for the specified date. This should return only one result in the
	 * normal case.
	 * 
	 * @param contextId
	 * @param date
	 * @return
	 */
	Collection<DistributionSchedule> getPitchSchedulesByPitchDate(Long contextId, Date date);
	
	/**
	 * Returns the most recent planner or pitch before the specified one
	 * 
	 * @param schedule
	 * @return
	 */
	<T extends Schedule> T getPreviousSchedule(T schedule);

	/**
	 * Returns the n most recent planners or pitch schedules before the specified one
	 * 
	 * @param schedule
	 * @return
	 */
	<T extends Schedule> Collection<T> getPreviousSchedules(T schedule, int count);
	
	/**
	 * Returns pitch schedules for a specified date and the status equal to any of the specified
	 * values in the status list.
	 * 
	 * @param contextId
	 * @param date
	 * @param status
	 * @return
	 */
	Collection<DistributionSchedule> getPitchSchedulesByPitchDate(Long contextId, Date date,
			ScheduleStatus... status);
}
