
import java.util.Calendar;
import java.util.Date;

/**
 * This class represents a TTC transfer. Each transfer has an issue date
 * and an issue station (the station at which the transfer is issued).
 * Transfer and Date form a composition. 
 *
 */
public class Transfer
{
	private String station;
	private Calendar calendar;
	
	/**
	 * Creates a transfer with the given station as its station
	 * and now as the given issue date.
	 * 
	 * @param station the station of the transfer.
	 * @pre. station != null
	 */
	public Transfer(String station)
	{
		this.station = station;
		this.calendar = Calendar.getInstance();
	}
	
	/**
	 * The day of the year at which this transfer has been issued. 
	 * 
	 * @return the day of the year at which this transfer has been issued.
	 */
	public int getDay()
	{
		return this.calendar.get(Calendar.DAY_OF_YEAR);
	}
	
	/**
	 * Returns the issue date of this transfer. 
	 * 
	 * @return the issue date of this transfer.
	 */
	public Date getIssueDate()
	{
		return this.calendar.getTime();
	}
	
	/**
	 * Returns the station at which this transfer has been issued. 
	 * 
	 * @return the station at which this transfer has been issued.
	 */
	public String getStation()
	{
		return this.station;
	}
	
	/**
	 * Tests if this transfer is the same as the given object,
	 * that is, the object is not null, it is an instance of this
	 * class and has the same issue date and station as this transfer.
	 * 
	 * @param obj Another object. 
	 * @return true if this transfer and the other object are the same,
	 *         false otherwise.
	 */
	@Override public boolean equals(Object obj)
	{
		boolean eq = false;
		if(this == obj)
		{
			eq = true;
		}
		else if(obj != null && this.getClass() == obj.getClass())
		{
			Transfer other = (Transfer) obj;
			eq = this.getStation().equals(other.getStation()) &&
			     this.getIssueDate().equals(other.getIssueDate());
		}
		return eq;
	}
	
	/**
	 * Returns a string representation of this transfer.
	 * This string consists of "Time issued: ",
	 * followed by the issue date, followed by ", Day: ",
	 * followed by the day of the year, followed by ",
	 * Not valid at: ", followed by the station. 
	 * 
	 * @return a string representation of this transfer.
	 */
	@Override public String toString()
	{
		String hour = String.valueOf(this.calendar.get(Calendar.HOUR));
		String minute = String.valueOf(this.calendar.get(Calendar.MINUTE));
		String am_pm = null;
		if (this.calendar.get(Calendar.AM_PM) == Calendar.AM)
		{
			am_pm = "A";
		}
		else
		{
			am_pm = "P";
		}
		String time = "Time issued: " + hour + ":" + minute + " " + am_pm;
		
		String day = ", Day: " + this.getDay();
		
		String station = ", Not valid at: " + this.getStation();
		
		return time + day + station;
	}
}
