// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define(["dojo/_base/array","dojo/Deferred","esri/request"],function(h,l,g){var d={},k=0;d.promisifyGetValue=function(a){var b=a.getValue;a.getValue=function(){var c=b.apply(a);if(null!==c&&c.then)return c;var e=new l;e.resolve(c);return e}};d.allowShareResult=function(a){return h.some(a.outputParams,function(b){return"GPRecordSet"===b.dataType||"GPFeatureRecordSetLayer"===b.dataType&&b.defaultValue&&b.defaultValue.geometryType})};d.getServiceDescription=function(a){var b;return g({url:a,content:{f:"json"},
handleAs:"json",callbackParamName:"callback"}).then(function(c){b=c;return d.getGPServerDescription(a).then(function(e){b.serverInfo=e;b.useResultMapServer=e.hasResultMapServer;return d.uploadSupported(e).then(function(f){b.serverInfo.supportsUpload=f.supportsUpload;"maxUploadFileSize"in f&&(b.serverInfo.maxUploadFileSize=f.maxUploadFileSize);return b})})})};d.getGPServerDescription=function(a){var b={url:d.getGPServerUrl(a),content:{f:"json"},handleAs:"json",callbackParamName:"callback"};return g(b,
{useProxy:!1}).then(function(c){var e={};e.currentVersion=c.currentVersion||0;e.url=b.url;e.hasResultMapServer="esriExecutionTypeAsynchronous"===c.executionType&&"resultMapServerName"in c&&""!==c.resultMapServerName;e.resultMapServerName=c.resultMapServerName;return e})};d.getGPServerUrl=function(a){if(!/\/GPServer\/.+$/.test(a))return"";var b=a.lastIndexOf("/");return a.substr(0,b+1)};d.getResultMapServerUrl=function(a,b){if(!/\/rest\/services\//.test(a))return"";var c=a.search(/\/rest\/services\//);
return a.substr(0,c+15)+b+"/MapServer"};d.uploadSupported=function(a){if(10.1<=a.currentVersion)return g({url:a.url+"uploads/info",content:{f:"json"},handleAs:"json"}).then(function(b){return{supportsUpload:!0,maxUploadFileSize:b.maxUploadFileSize}},function(){return{supportsUpload:!1}});a=new l;a.resolve({supportsUpload:!1});return a};d.getResultMapLayers=function(a,b){a={url:d.getResultMapServerUrl(a,b),content:{f:"json"},handleAs:"json",callbackParamName:"callback"};return g(a,{useProxy:!1}).then(function(c){var e=
h.map(c.layers,function(f){return f.name});h.forEach(c.tables,function(f){e.push(f.name)});return e})};d.useDynamicSchema=function(a,b){return"useDynamicSchema"in a?!0===a.useDynamicSchema:!0===b.useDynamicSchema};d.uniqueId=function(){var a=Date.now();a<=k?a=++k:k=a;return a};return d});