package employees.model
{
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;
	import mx.rpc.remoting.RemoteObject;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	
	public class LoadEmployeesProxy extends Proxy {
		public static const NAME:String = 'LoadEmployeesProxy';
		public static const LOAD_EMPLOYEES_SUCCESS:String = 'loadEmployeesSuccess';
		public static const LOAD_EMPLOYEES_FAILED:String  = 'loadEmployeesFailed';
		
		private var employeeServiceRO:RemoteObject;
		
		public function LoadEmployeesProxy() {
			super(NAME);
			
			employeeServiceRO = new RemoteObject();
			employeeServiceRO.destination = "employeeServiceDest";
			employeeServiceRO.addEventListener(ResultEvent.RESULT, onResult);
			employeeServiceRO.addEventListener(FaultEvent.FAULT, onFault);
		}
		
		public function load():void {
			employeeServiceRO.getList();
		}
		
		private function onResult(event:ResultEvent):void {
			sendNotification(LOAD_EMPLOYEES_SUCCESS, event.result);
		}
		
		private function onFault(event:FaultEvent):void {
			sendNotification(LOAD_EMPLOYEES_FAILED, event.fault.faultString);
		}
	}
}