/**
 * Widget client singleton that allows widgets to communicate with an
 * Orchestra host page.
 */

var qmatic = qmatic || {};
qmatic.connector = qmatic.connector || {};

(function() {
	
	/** @namespace */ 
	qmatic.connector.client = (function() {
		
		/** @private */
		function initialize() {
			
		}
		
		/** @scope qmatic.connector.client */
		return {
			
			/**
			 * Gets all available branches.
			 * 
			 * @return List of TinyBranch, Empty list if no branches found.
			 */
			getBranches : function(){
				var params = {};
		    	return WidgetConnector.getBranches(params);
			},

			/**
			 * Gets the branch for this id.
			 * 
			 * @param branchId
			 *              id of branch
			 * @return TinyBranch
			 */
		    getBranch : function(branchId) {
		    	var params = {
		    		'branchId':branchId
		    	};
		    	return WidgetConnector.getBranch(params);
		    },

			/**
			 * Gets all available queues for this branch.
			 * 
			 * @param branchId
			 *            id of branch
			 * 
			 * @return A list of TinyQueue. Empty list if no queues found.
			 */
		    getQueues : function(branchId) {
		    	var params = {
		    		'branchId':branchId
		    	};
		    	return WidgetConnector.getQueues(params);
		    },

			/**
			 * Gets the queue for this queue id
			 * 
			 * @param branchId
			 *            id of branch
			 * @param queueId
			 *            logic id of the queue
			 * @return TinyQueue
			 */
		    getQueue : function(branchId, queueId) {
		    	var params = {
		    		'branchId':branchId,
		    		'queueId':queueId
		    	};
		    	return WidgetConnector.getQueue(params);
		    },

			/**
			 * Get the service type for this branch identified with a specific service type ID
			 * 
			 * @param branchId
			 *            id of branch
			 * @param serviceId
			 *            logic id of the service.
			 * @return Service
			 */
		    getService : function(branchId, serviceId) {
		    	var params = {
		    		'branchId':branchId,
		    		'serviceId':serviceId
		    	};
		    	return WidgetConnector.getService(params);
		    },

			/**
			 * Gets all available service types for a branch.
			 * 
			 * @param branchId
			 *            id of branch
			 * 
			 * @return List of Service. Empty list if no services found.
			 */
		    getServices : function(branchId){
		    	var params = {
		    		'branchId':branchId
		    	};
		    	return WidgetConnector.getServices(params);
		    },

 		    /**
 		     * Creates a new Visit. (depreceated)
 		     * 
		     * @param branchId
		     *            id of branch
		     * @param entryPointId
		     *            logic id of the entry point e.g. 1 or 2 or 3 etc
 		     *            VisitParameters
 		     * @return Visit
 		     */
		    createVisit : function(branchId, entryPointId, visitParams) {
 		    	var params = {
		    		'branchId':branchId,
		    		'entryPointId':entryPointId
 		    	};
 		    	params.$entity = visitParams;
 		    	return WidgetConnector.createVisit(params);
 		    },

		    /**
		     * Creates a new Visit.
		     * 
		     * @param unitId
		     *            unit id of the entry point 
		     * @param params
		     *            VisitParameters
			 * @param sortPolicy (optional)
			 *			  position inserted in queue: FIRST, LAST, SORTED
		     * @return Visit
		     */
		    createVisitByUnitId : function(unitId, visitParams, sortPolicy) {
		    	var params = {};
				params.unitId = unitId;
				
				if(sortPolicy != undefined)
					params.sortPolicy = sortPolicy;
		    		
		    	params.$entity = visitParams;
		    	return WidgetConnector.createVisitByUnitId(params);
		    },
			
			/**
			 * Returns the visit specified by id.
			 * 
			 * @param branchId
			 *            id of the branch
			 * @param visitId
			 *            id of the visit
			 * @return Visit
			 */
			 getVisit : function(branchId, visitId) {
 		    	var params = {
 		    		'branchId':branchId,
 		    		'visitId':visitId
 		    	};
 		    	return WidgetConnector.getVisit(params);
			 },
			
			/**
			 * Returns the available service points for the given branch that have at least one device of the type identified by the device code.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param deviceType
			 *            A string identifying a device type 
			 *   		  GW1745, BP, TP311X, DMATRIX, D7SEGM, Cinematic, KT, MI2280, SI2477, CI2477, VU, Choral, SW_WORKSTATION, SW_RECEPTION,
			 *			  SW_TP3115_TOUCH, SW_VISION15_TOUCH, SW_VISION17_TOUCH, SW_MEDIA_HD_POSITIONAL_DISPLAY_POINT, SW_MEDIA_HD_DISPLAY_POINT,
			 *			  SW_MEDIA_FULL_HD_DISPLAY_POINT, SW_VISITAPP, SW_MEDIA_HD_POSITIONAL_DISPLAY_POINT_PORTRAIT, SW_MEDIA_HD_DISPLAY_POINT_PORTRAIT,
			 *			  SW_MEDIA_FULL_HD_DISPLAY_POINT_PORTRAIT, SW_INTRO17_TOUCH
			 * @return List of ServicePoint. Empty List if no service point found.
			 */
		    getServicePointsByDeviceType : function(branchId, deviceType) {
		    	var params = {
		    		'branchId':branchId,
		    		'deviceType':deviceType
		    	};
		    	return WidgetConnector.getServicePointsByDeviceType(params);
		    },
			
			/**
			 * Retrieve a particular entry point.
			 * 
			 * @param unitId
			 *            unit id of entry point
			 * @return EntryPoint
			 */
			getEntryPointByUnitId : function(unitId) {
		    	var params = {
		    		'unitId':unitId
		    	};
		    	return WidgetConnector.getEntryPointByUnitId(params);
			},
			
 			/**
 			 * Retrieve a particular entry point. (depreceated)
 			 * 
			 * @param branchId
			 *            id of branch
			 * @param entryPointId
			 *            logic id of entry point
 			 * @return EntryPoint
 			 */
			getEntryPoint : function(branchId, entryPointId) {
 		    	var params = {
		    		'branchId':branchId,
		    		'entryPointId':entryPointId
 		    	};
 		    	return WidgetConnector.getEntryPoint(params);
 			},
						
			/**
			 * Get a list of Users that are currently logged in on a service point on the specified branch. By default all users logged in on both service
			 * points and entry points will be returned. By setting parameter "onlyServicePoints" to true, only users
			 * that are logged in on a service point will be returned
			 * 
			 * @param branchId
			 *            id of branch
			 * @param onlyServicePoints
			 *            set to "true" to filter out users logged in to entrypoints.
			 * 
			 * @return List of User. Empty list if no users found.
			*/
			getLoggedInUsers : function(branchId, onlyServicePoints) {
		    	var params = {
		    		'branchId':branchId,
					'onlyServicePoints':onlyServicePoints
		    	};
		    	return WidgetConnector.getLoggedInUsers(params);
			},
			
			/**
			 * Gets all visits that are in a waiting state, i.e. not called, for the Queue identified by this queueId, in the specified branch id.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param queueId
			 *            logic id of the queue
			 * @return A list of TinyVisit
			 */
			getVisitsInQueue : function(branchId, queueId) {
		    	var params = {
		    		'branchId':branchId,
		    		'queueId':queueId
		    	};
		    	return WidgetConnector.getVisitsInQueue(params);
			},
			
			/**
			 * Searches for Visits based on the parameters in the supplied search filter.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param filterParams
			 *            search filter
			 * @return List of TinyVisit. Empty list if no visits found.
			 */
			findVisits : function(branchId, filterParams) {
		    	var params = {
		    		'branchId':branchId
		    	};
				params.$entity = filterParams;
		    	return WidgetConnector.findVisits(params);
			},
			
			/**
			 * Transfer a visit to a service point pool.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param servicePointId
			 *            logic id of service point.
			 * @param transferParams
			 *            TransferParams
			 */
			transferVisitToServicePointPool : function(branchId, servicePointId, transferParams) {
		    	var params = {
		    		'branchId':branchId,
		    		'servicePointId':servicePointId
		    	};
				params.$entity = transferParams;
		    	return WidgetConnector.transferVisitToServicePointPool(params);
			},
			
			/**
			 * Transfer visit to a user pool.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param userId
			 *            logic id of user.
			 * @param transferParams
			 *            TransferParams
			 */
			transferVisitToUserPool : function(branchId, userId, transferParams) {
		    	var params = {
		    		'branchId':branchId,
		    		'userId':userId
		    	};
				params.$entity = transferParams;
		    	return WidgetConnector.transferVisitToUserPool(params);
			},
			
			/**
			 * Transfer visit to a queue.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param queueId
			 *            logic id of queue.
			 * @param transferParams
			 *            TransferParams
			 */
			transferVisitToQueue : function(branchId, queueId, transferParams) {
		    	var params = {
		    		'branchId':branchId,
		    		'queueId':queueId
		    	};
				params.$entity = transferParams;
		    	return WidgetConnector.transferVisitToQueue(params);
			},
			
			/**
			 * Returns all available display points on the given branch, having at least one device of the type identified by the devicecode. 
			 * 
			 * @param branchId
			 *            id of branch
			 * @param deviceType
			 *            A string identifying a device type 
			 *   		  GW1745, BP, TP311X, DMATRIX, D7SEGM, Cinematic, KT, MI2280, SI2477, CI2477, VU, Choral, SW_WORKSTATION, SW_RECEPTION,
			 *			  SW_TP3115_TOUCH, SW_VISION15_TOUCH, SW_VISION17_TOUCH, SW_MEDIA_HD_POSITIONAL_DISPLAY_POINT, SW_MEDIA_HD_DISPLAY_POINT,
			 *			  SW_MEDIA_FULL_HD_DISPLAY_POINT, SW_VISITAPP, SW_MEDIA_HD_POSITIONAL_DISPLAY_POINT_PORTRAIT, SW_MEDIA_HD_DISPLAY_POINT_PORTRAIT,
			 *			  SW_MEDIA_FULL_HD_DISPLAY_POINT_PORTRAIT, SW_INTRO17_TOUCH
			 * @return List of PresentationPoint
			 */
			getPresentationPointsByDeviceType : function(branchId, deviceType) {
		    	var params = {
		    		'branchId':branchId,
		    		'deviceType':deviceType
		    	};
		    	return WidgetConnector.getPresentationPointsByDeviceType(params);
			},
			
			/**
			 * Returns the status for the workstation associated with the supplied unitId and branchId. This method is typically used by a Positional Display.
			 * 
			 * @param branchId
			 *            id of branch
			 * @param unitId
			 *            The display unitId
			 * @return A ServicePointStatus instance with the current status of the workstation identified by the supplied parameters.
			 */
			getServicePointStatusForDisplay : function(branchId, unitId) {
		    	var params = {
		    		'branchId':branchId,
		    		'unitId':unitId
		    	};
		    	return WidgetConnector.getServicePointStatusForDisplay(params);
			},
			
			/** 
			 * Gets queue MI data for a specified branch.
			 *
			 * @param branchId
			 *			id of branch
			 * @return List of QueueData
			 */
			getQueueData : function(branchId) {
		    	var params = {
		    		'branch':branchId
		    	};
		    	return WidgetConnector.getQueueData(params);
			},
			
			/** 
			 * Gets visit MI data for a specified branch.
			 *
			 * @param branchId
			 *			id of branch
			 * @param queueId
			 *			id of queue
			 * @return List of VisitData
			 */
			getVisitData : function(branchId, queueId) {
		    	var params = {
		    		'branch':branchId,
		    		'queue':queueId
		    	};
		    	return WidgetConnector.getVisitData(params);
			},
			
			/** 
			 * Gets servicePoint MI data for a specified branch.
			 *
			 * @param branchId
			 *			id of branch
			 * @return List of ServicePointData
			 */
			getServicePointData : function(branchId) {
		    	var params = {
		    		'branch':branchId
		    	};
		    	return WidgetConnector.getServicePointData(params);
			},
			
			/**
			 * Get the currently logged in user(s) for a service-point.
			 *
			 * (many users may be logged in to the same service point)
			 *
			 * @param branchId
			 *			id of branch
			 * @param servicePointId
			 *			id of servicePoint
			 * @return List of User
			 */
			getCurrentLoggedInUsers : function(branchId, servicePointId) {
		    	var params = {
		    		'branch':branchId,
		    		'servicepoint':servicePointId
		    	};
		    	return WidgetConnector.getCurrentLoggedInUsers(params);
			},
			
			/**
			 * Get all appointments for a branch.
			 * 
			 * @param branchId 
			 *              id of the branch
			 * @return Appointment
			 */
			getAppointmentsForBranch : function(branchId) {
		    	var params = {
		    		'branchId':branchId
		    	};
		    	return WidgetConnector.getAppointmentsForBranch(params);
			},
			
			/**
			 * Get the appointment for this branch identified with a specific id
			 * 
			 * @param branchId
			 *              id of the branch
			 * @param appointmentId
			 *              id of the appointment
			 * @return Appointment
			 */
			getAppointmentForBranch : function(branchId, appointmentId) {
		    	var params = {
		    		'branchId':branchId,
					'appointmentId':appointmentId
		    	};
		    	return WidgetConnector.getAppointmentForBranch(params);
			},
			
			/**
			 * Get the appointment identified by its externalId.
			 * 
			 * @param externalId
			 *              externalId 
			 * @return Appointment
			 */
			getAppointmentByExternalId : function(externalId) {
		    	var params = {
		    		'externalId':externalId
		    	};
		    	return WidgetConnector.getAppointmentByExternalId(params);
			},
			
			/**
			 * Search for appointments.
			 * 
			 * @return List of Appointment. Empty list if no appointments found.
			 */
			findAppointments : function(findParams) {
				var params = {};
				params.$entity = findParams;
				return WidgetConnector.findAppointments(params);
			},
			
			/**
			 * Get an appoitment customer identified by its id
			 * 
			 * @param customerId 
			 *              id of the customer
			 * @return GenericCustomer
			 */
			getAppointmentCustomer : function(customerId) {
		    	var params = {
		    		'customerId':customerId
		    	};
		    	return WidgetConnector.getAppointmentCustomer(params);
			},
			
			/**
			 * Search for an appointment customer.
			 * 
			 * @return List of GenericCustomer. Empty list if no customers found.
			 */
			findAppointmentCustomers : function(findParams) {
				var params = {};
				params.$entity = findParams;
				return WidgetConnector.findAppointmentCustomers(params);
			},
			
			/**
			 * Get the customer identified by its id
			 * 
			 * @param customerId 
			 *              id of the customer
			 * @return GenericCustomer
			 */
			getCustomer : function(customerId) {
		    	var params = {
		    		'customerId':customerId
		    	};
		    	return WidgetConnector.getCustomer(params);
			},
			
			/**
			 * Search for a customer.
			 * 
			 * @return List of GenericCustomer. Empty list if no customers found.
			 */
			findCustomers : function(findParams) {
				var params = {};
				params.$entity = findParams;
				return WidgetConnector.findCustomers(params);
			},
			
			/**
			 * Update a customer.
			 * 
			 * @param customerId 
			 *              id of customer
			 * @param GenericCustomer
			 */
			updateCustomer : function(customerId, customer) {
		    	var params = {
		    		'customerId':customerId
		    	};
				params.$entity = customer;
		    	return WidgetConnector.updateCustomer(params);
			},
			
			/**
			 * Retrieve a global variable. Global variable are accessible from all branches.
			 * 
			 * @param name
			 *            name of global variable.
			 * @return GlobalVariable
			 */
			getGlobalVariable : function(name) {
		    	var params = {
		    		'name':name
		    	};
		    	return WidgetConnector.getGlobalVariable(params);
			},
			
			/**
			 * Set the value (or create new) for a global variable.
			 * 
			 * @param name
			 *            name of global variable
			 * @param value
			 *            value of global variable
			 */
			setGlobalVariable : function(name, value) {
				var params = {};
				params.$entity = {'name':name, 'value':value};
				return WidgetConnector.setGlobalVariable(params);
			},
			
			/**
			 * Retrieve a list of all global variables.
			 * 
			 * @return A list of GlobalVariable. Empty list when no global variables are found.
			 */
			getGlobalVariables : function() {
				return WidgetConnector.getGlobalVariables();
			},
			
			/**
			 * Delete a global variable.
			 * 
			 * @param name
			 *            The variable to delete.
			 */
			deleteGlobalVariable : function(name) {
		    	var params = {
		    		'name':name
		    	};
		    	return WidgetConnector.deleteGlobalVariable(params);
			},
			
			/**
			 * Retrieve a branch variable.
			 * 
			 * @param branchId
			 *            id of branch.
			 * @param name
			 *            name of branch variable.
			 * @return GlobalVariable
			 */
			getBranchVariable : function(branchId, name) {
		    	var params = {
					'branchId':branchId,
		    		'name':name
		    	};
		    	return WidgetConnector.getBranchVariable(params);
			},
			
			/**
			 * Set the value of (or create new) branch variable.
			 * 
			 * @param branchId
			 *            id of branch.
			 * @param name
			 *            name of branch variable.
			 * @param value
			 *            value of branch variable.
			 */
			setBranchVariable : function(branchId, name, value) {
		    	var params = {
					'branchId':branchId,
		    		'name':name
		    	};
				params.$entity = {'name':name, 'value':value};
				return WidgetConnector.setBranchVariable(params);
			},
			
			/**
			 * Retrieve a list of all branch variables for specified branch.
			 * 
			 * @param branchId
			 *            id of branch.
			 * @return List of GlobalVariable
			 */
			getBranchVariables : function(branchId) {
		    	var params = {
					'branchId':branchId
		    	};
		    	return WidgetConnector.getBranchVariables(params);
			},
			
			/**
			 * Delete the branch variable specifed by name.
			 * 
			 * @param branchId
			 *            id of branch.
			 * @param name
			 *            name of branch variable.
			 */
			deleteBranchVariable : function(branchId, name) {
		    	var params = {
					'branchId':branchId,
		    		'name':name
		    	};
				return WidgetConnector.deleteBranchVariable(params);
			},
			
			/**
			 * Adds a mark to visit.
			 * @param branchId
			 *            id of branch.
			 * @param visitId
			 *            id of visit.
			 * @param markId
			 *            id of mark.
			 * @param servicePointId
			 *            id of service point
			 */
			 addMark : function(branchId, visitId, markId, servicePointId) {
				var params = {
					'branchId' : branchId,
					'visitId' : visitId,
					'markId' : markId,
					'servicePointId' : servicePointId
				};
				return WidgetConnector.addMark(params);
			 },
			 
			/**
			 * Adds a mark to visit.
			 * @param branchId
			 *            id of branch.
			 * @param visitId
			 *            id of visit.
			 * @param markId
			 *            id of mark.
			 * @param servicePointId
			 *            id of service point
			 */
			 addMarkByName : function(branchId, visitId, markName, servicePointId) {
				var params = {
					'branchId' : branchId,
					'visitId' : visitId,
					'markName' : markName,
					'servicePointId' : servicePointId
				};
				return WidgetConnector.addMarkByName(params);
			 }
			 
			 
		};

		initialize();

	})();
})();
