define([ "dojo/_base/array", // array.forEach array.map
"dojo/_base/declare", // declare
"dojo/_base/event", // event.stop
"dojo/_base/lang", // lang.getObject, lang.hitch
"dojo/on",
"dojo/Deferred",
"dojox/rpc/Service",
"obno/core/rpc/JsonRPC",
"dojox/json/ref"
], function(array, declare, event, lang, on, Deferred) {

	var fixupUrl= function(url){
		var cacheBust = dojo.config.cacheBust;
		if (cacheBust){
			url += ""; // make sure url is a Javascript string (some paths may be a Java string)
			return url + (cacheBust ? ((/\?/.test(url) ? "&" : "?") + cacheBust) : "");			
		}
		return url;
	};

	var module = declare("obnogen.service.com.obno.core.DebugService", null, {
		//cache bust the schemas
		svc : new dojox.rpc.Service(fixupUrl(require.toUrl("obnogen.service.com.obno.core.DebugService".replace(/\./g,"/")).replace(/\/[^\/]+$/,"/")  + "../../../../../../com/obno/json/schema/com/obno/core/DebugService")),

		JSONRefArgs: {
			idAttribute	: '__jsonRefID'
		},

		constructor: function(){
		},
		debug : function(msg ){	
			try
			{
				var self = this;
				var deferred = new Deferred();
				this.svc.debug({msg : msg }).then(
					function(data)
					{
						//de-reference any JSON References
						if (lang.isArray(data)){
							var derefedData = [];
							var index = {};
							var derefArgs = lang.mixin({"index": index}, self.JSONRefArgs);
							lang.forEach(data, function(d){
								derefedData.push(dojox.json.ref.resolveJson(d, derefArgs));
							});
							data = derefedData;
						}
						else {
							data = dojox.json.ref.resolveJson(data, self.JSONRefArgs);
						}
						deferred.resolve([]);
					},
					function(err)
					{
						deferred.reject([err.message]);
					}
				);
				return deferred;
			}
			catch (e)
			{
				throw e;
			}
		}	

	});

	return module;

});