/**************************************************************
	DO NOT MODIFY THIS FILE
	File is create automatically by
	Hivext WSDL2JS XSL Transformation Utility
**************************************************************/

var GBatchHttpSwitcher = false;

HNamespace.Define("Utils", {

	BatchService : HClass.Define("Utils.BatchService", { extend : HWebService.Provider, props : {

		construct : function() {},

		ConstructClient : function() {
			var oClient = new this.BatchPortType;
			oClient.oServiceBind = new this.BatchBinding;
			return oClient;
		},

		BatchPort : HClass.Define("BatchPort", { extend : HRest.Client, props : {
			sNamespace : "http://api.hivext.ru/1.0/utils/batch/cross/",
			sLocation : "http://api.hivext.ru/1.0/utils/batch/cross/",
			construct : function() {}
		}}),

		BatchBinding : HClass.Define("BatchBinding", { extend : BatchPort, props : {
			aOperationLocation : {
				Call : "call"
			},

			construct : function() {}

		}}),

		BatchPortType : HClass.Define("BatchPortType", { props : {
			oServiceBind : null,

			construct : function() {},

			CallInput : {
				appid : "string",
				request : "string",
				sync : "boolean"
			},

			CallOutput : {
				result : "int",
				error : "string",
				response : "string"
			},

			Call : function() {
				var oServiceBind = this.oServiceBind;
				if(!oServiceBind) { throw Error("Method name : Call : binding not found"); }
				var sUrl = oServiceBind.ConstructUrl("Call");
				var fnCallback = HWebService.Client.FindCallback(arguments);

				if(GBatchHttpSwitcher) {
					// Construct request.
					sUrl += "?" + oServiceBind.ConstructRequest(arguments, this.CallInput);	
					// Send request.
					var CallInput = this.CallInput;
					(new HNet.ScriptRequest()).Get(sUrl, function(oResponse) {
						if(fnCallback) fnCallback(oResponse);
					});
				} else {
					// Construct request.
					var oParams = oServiceBind.ConstructParams(arguments, this.CallInput);
					var CallOutput = this.CallOutput;
					// Send request.
					(new HNet.WNTransport()).Post(sUrl, oParams, function(sResponse) {
						var oResponse = oServiceBind.ConstructResponse(sResponse, CallOutput);
						if(fnCallback) fnCallback(oResponse);
					});
				}

			}

		}})

	}})

});

// !!! STATIC LINK !!!
Utils.Batch = (new Utils.BatchService).ConstructClient();
// !!! STATIC LINK !!!
