define([
	'Global',
	'Consult'
],
	function(Global, Consult) {
		var ConsultOrders = Backbone.Collection.extend({
			model: Consult,
			parse: function(response) {
				this.currentPage = response.currentPage || 1;
				this.pageCount = response.pageCount;
				this.recordCount = response.recordCount || response.size;
				this.startRecord = response.startRecord;
				this.stopRecord = response.stopRecord || response.size;

				var objectType = response["object-type"];

				objectType = objectType.substr(0, objectType.length - 1);

				if (objectType.substr(0, 2) !== "SM") {
					objectType = objectType.toLowerCase();
				}

				return response[objectType];
			},
			initialize: function() {
			},
			findById: function(id) {
				return this.find(function (model) {
					return model.get('consultIen') === id;
				});
			}
		});

		ConsultOrders.singleInstance = null;

		ConsultOrders.instance = function () {
			ConsultOrders.singleInstance = ConsultOrders.singleInstance || new ConsultOrders();
			return ConsultOrders.singleInstance;
		};

		return ConsultOrders;
	}
);
