/**
 * 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.assetlist.IAssetListSearchService;
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.watchpoint.pmm.entities.Title;

/**
 * Schedule search interface
 * 
 * @author Sahil Verma
 */
public interface IScheduleSearchService extends IAssetListSearchService<Schedule> {
	
	/**
	 * 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);
	
	/**
	 * Finds the earliest planner for the given title. 
	 * 
	 * @param title
	 * @return
	 */
	Long findEarliestUpcomingPlannerId(Title title);
}
