define([
	'Global',
	'LocationServiceResources',
	'PatientSearchResource',
	'User'
],
	function(Global, locationServiceResources, patientSearchResource, user){
		var singleInstance,
			SearchModel = Backbone.Model.extend({
			defaults: {
				'title': 'Patient',
				'url': '',
				'searchOption': 'search',/* none: NO search or filter inputs
											search: Search input only
											filter-search: search AND filter inputs
											*/
				'dropDownContent': { // searchstring, ward, clinic
					'Patient': {url: "#", searchOption:"search", default: true},
					'Ward': {url: "#", searchOption:"filter-search"},
					'Clinic': {url:"#", searchOption:"filter-search"},
					'Last 20':{url: "#", searchOption:"none"}
				},
				results:[]
			},
			initialize: function(){
				var URL = '#',
					clinic = locationServiceResources.instance().get('clinics-operational'),
					ward = locationServiceResources.instance().get('wards-operational'),
					last20 = patientSearchResource.instance();
				if(typeof user.get('patients-operational') !== 'undefined'){
					URL = user.get('patients-operational').href;
					this.toJSON().dropDownContent['Patient'].url =  URL;
					this.set('url', URL);
				}
				if(typeof ward !== 'undefined'){
					URL = ward.get('href');
					this.toJSON().dropDownContent['Ward'].url =  URL;
				}
				if(typeof clinic !== 'undefined'){
					URL = clinic.get('href');
					this.toJSON().dropDownContent['Clinic'].url =  URL;
				}
				if(typeof last20 !== 'undefined'){
					if( typeof last20.get('recent') !== 'undefined')
						{
							URL = last20.get('recent').get('href');
						}
					this.toJSON().dropDownContent['Last 20'].url =  URL;
				}

			},
			getActions: function(){
				var actions = [],
					options = this.get('dropDownContent');

				for(var item in options){
					options[item].text = item;
					actions.push(options[item]);
				}

				return actions
			}
		});
		SearchModel.instance = function() {
			if (typeof singleInstance === "undefined") {
				singleInstance = new SearchModel();
			}
			return singleInstance;
		};

		return SearchModel;
	}
);