package scheduleGenerator;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

/**
 * TODO Put here a description of what this class does.
 * 
 * @author saslavns. Created Oct 29, 2012.
 */
public class PeopleWriter {
	private FileWriter out;
	private ArrayList<Person> people;

	/**
	 * TODO Put here a description of what this constructor does.
	 *
	 * @param filename
	 * @param people
	 */
	public PeopleWriter(String filename, ArrayList<Person> people) {
		try {
			this.out = new FileWriter(filename);
		} catch (IOException exception) {
			exception.printStackTrace();
		}
		this.people = people;
	}

	/**
	 * TODO Put here a description of what this method does.
	 *
	 */
	public void writeFile() {
		for (Person p : this.people) {
			try {
				this.out.write(":" + p.getName() + "\n");
				for (String date : p.getAvailability().keySet()) {
					this.out.write("+" + date + "\n");
					for (String timeOfDay : p.getAvailability().get(date)) {
						this.out.write("~" + timeOfDay + "\n");
					}
					// out.write(date.substring(4, 10) + "," +
					// date.substring(date.length()-5, date.length()));
				}
				for (String job : p.getJobs()) {
					this.out.write("!" + job + "\n");
				}
				this.out.write("%" + "\n");
			} catch (IOException exception) {
				exception.printStackTrace();
			}

		}
		try {
			this.out.close();
		} catch (IOException exception) {
			// TODO Auto-generated catch-block stub.
			exception.printStackTrace();
		}
	}
}
