/**
 * Notification.java
 * Created Jul 2, 2008
 * Copyright (c) TANDBERG Television 2007-2008
 */
package com.tandbergtv.watchpoint.pmm.schedule.notify;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import com.tandbergtv.watchpoint.pmm.entities.Schedule;
import com.tandbergtv.watchpoint.pmm.entities.Title;

/**
 * A notification indicates that titles within a schedule failed to get to a certain predefined
 * progress status value by some deadline
 * 
 * @author Sahil Verma
 */
public class Notification {
	
	private Collection<Title> titles;
	
	private Schedule schedule;
	
	private Collection<String> messages;

	/**
	 * Creates a Notification
	 * @param schedule
	 */
	public Notification(Schedule schedule) {
		this.schedule = schedule;
		this.titles = new HashSet<Title>();
		this.messages = new ArrayList<String>();
	}

	/**
	 * @return the schedule
	 */
	public Schedule getSchedule() {
		return this.schedule;
	}
	
	/**
	 * @return the messages
	 */
	public Collection<String> getMessages() {
		return this.messages;
	}
	
	/**
	 * Adds the specified message
	 * 
	 * @param message
	 */
	public void addMessage(String message) {
		this.messages.add(message);
	}

	/**
	 * @return the titles
	 */
	public Collection<Title> getTitles() {
		return this.titles;
	}

	/**
	 * Adds the title to this notification
	 * @param title
	 */
	public void addTitle(Title title) {
		this.titles.add(title);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return this.messages.size() + " warnings for " + this.schedule;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.schedule == null) ? 0 : this.schedule.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Notification))
			return false;
		Notification other = (Notification) obj;
		if (this.schedule == null) {
			if (other.schedule != null)
				return false;
		} else if (!this.schedule.equals(other.schedule))
			return false;
		return true;
	}
}
