package alpaca;
import java.util.*;

/**
 * @author Sylvia Allain, Jonathan Cole
 * 
 * Holds information about the environment the alpacas reside in.
 * High/Low tolerances for temperature, fence boundaries, etc.
 * 
 * Variables will be pulled from FireBase, and set by the 
 * User Preference interface.
 */
public class PacaWorld {
	
	public List<PacaEvent> alerts = new ArrayList<PacaEvent>();
	private float longitudeFloor = -180f;
	private float longitudeCeiling = 180f;
	private int numSatellites = 100;
	private float altitudeFloor = 0;
	private float altitudeCeiling = 8900;
	private float temperatureFloor = -140f;
	private float temperatureCeiling = 4000f;

	public PacaWorld() {
		
	}
	
	/**
	 * Creates an event and passes it to both the list of events and FireBase.
	 * @param alp
	 * @param type
	 */
	public void CreateAlert(Alpaca alp, PacaEvent.EventType type){
		PacaEvent e = new PacaEvent(alp, type);
		alerts.add(e);
		//Add to firebase
	}
	
	public void setLongitudeFloor(float floor) { this.longitudeFloor = floor; }
	
	public void setLongitudeCeiling(float ceiling) { this.longitudeCeiling = ceiling; }
	
	public void setNumSatellites(int numSatellites) { this.numSatellites = numSatellites; }
	
	public void setAltitudeFloor(float floor) { this.altitudeFloor = floor; }
	
	public void setAltitudeCeiling(float ceiling) { this.altitudeCeiling = ceiling; }
	
	public void setTemperatureFloor(float floor) { this.temperatureFloor = floor; }
	
	public void setTemperatureCeiling(float ceiling) { this.temperatureCeiling = ceiling; }
	
	public float returnLongitudeFloor() { return longitudeFloor; }
	
	public float returnLongitudeCeiling() { return longitudeCeiling; }
	
	public int returnNumSatellites() { return numSatellites; }
	
	public float returnAltitudeFloor() { return altitudeFloor; }
	
	public float returnAltitudeCeiling() { return altitudeCeiling; }
	
	public float returnTemperatureFloor() { return temperatureFloor; }
	
	public float returnTemperatureCeiling() { return temperatureCeiling; }
	
}
@@ -30,16 +30,184 @@
 til.*;%0A%0A
+import com.firebase.client.ChildEventListener;%0Aimport com.firebase.client.DataSnapshot;%0Aimport com.firebase.client.Firebase;%0Aimport com.firebase.client.FirebaseError;%0A%0A
 /**%0A * @
@@ -829,16 +829,40 @@
 = 4000f;
+%0A%09private HashMap alert;
 %0A%0A%09publi
@@ -879,16 +879,38 @@
 d() %7B%0A%09%09
+alert = new HashMap();
 %0A%09%7D%0A%09%0A%09/
@@ -1094,84 +1094,765 @@
 %7B%0A%09%09
-PacaEvent e = new PacaEvent(alp, type);%0A%09%09alerts.add(e);%0A%09%09//Add to firebase
+Firebase alertRef = new Firebase(%22https://crackling-fire-2064.firebaseio.com/alerts%22).push();%0A%09%09PacaEvent e = new PacaEvent(alp, type);%0A%09%09%0A%09%09// build hashmap of alert to store in Firebase%0A%09%09alert.put(%22alpacaID%22, alp.getTrackerID());%0A%09%09alert.put(%22read%22, e.readByUser);%0A%09%09alert.put(%22message%22, e.ToString());%0A%09%09alert.put(%22priority%22, e.priority.toString());%0A%0A%09%09alerts.add(e);%0A%09%09%0A%09%09// save alert in Firebase%0A%09%09alertRef.setValue(alert, new Firebase.CompletionListener() %7B%09%09%0A%09%09%09@Override%0A%09%09%09public void onComplete(FirebaseError error, Firebase arg1) %7B%0A%09%09%09%09if (error != null) %7B%0A%09%09            System.err.println(%22Data could not be saved: %22 + error.getMessage());%0A%09%09        %7D else %7B%0A%09%09            System.out.println(%22Data saved successfully.%22);%0A%09%09        %7D%0A%09%09%09%7D%0A%09%09%7D);
 %0A%09%7D%0A

save alerts into firebase upon creation