import{__decorate}from"tslib";import RouteParameters from"@arcgis/core/tasks/support/RouteParameters";import{isArcGisApiVersionAtLeast}from"./ArcGisApiVersion.js";import{validation}from"../../Validation.js";import{inline,isAbortable,schedulePromiseCancellation}from"./tools.js";import{MapProvider}from"./MapProvider.js";import{activate}from"../../Hooks.js";import EsriRouteTask from"@arcgis/core/tasks/RouteTask";let RouteTask=class{execute(i,e,t){var r=validation.string("url",i.url,validation.never);const o=new RouteParameters;o.stops=validation.exists("stops",i.stops),o.accumulateAttributes=validation.array("accumulateAttributes",i.accumulateAttributes),o.attributeParameterValues=validation.exists("attributeParameterValues",i.attributeParameterValues,void 0);let a=validation.exists("pointBarriers",i.pointBarriers,void 0);a=a||validation.exists("barriers",i.barriers,void 0),isArcGisApiVersionAtLeast("4.11")?o.pointBarriers=a:o.barriers=a,o.directionsLanguage=validation.string("directionsLanguage",i.directionsLanguage,void 0),o.directionsLengthUnits=validation.string("directionsLengthUnits",i.directionsLengthUnits,void 0),o.directionsOutputType=validation.string("directionsOutputType",i.directionsOutputType,void 0),o.directionsStyleName=validation.string("directionsStyleName",i.directionsStyleName,void 0),o.directionsTimeAttribute=validation.string("directionsTimeAttribute",i.directionsTimeAttribute,void 0),o.doNotLocateOnRestrictedElements=validation.boolean("doNotLocateOnRestrictedElements",i.doNotLocateOnRestrictedElements,void 0),o.findBestSequence=validation.boolean("findBestSequence",i.findBestSequence,void 0),o.ignoreInvalidLocations=validation.boolean("ignoreInvalidLocations",i.ignoreInvalidLocations,void 0),o.impedanceAttribute=validation.string("impedanceAttribute",i.impedanceAttribute,void 0),o.impedanceAttribute||(o.impedanceAttribute=validation.string("impedenceAttribute",i.impedenceAttribute,void 0)),o.outputGeometryPrecision=validation.number("outputGeometryPrecision",i.outputGeometryPrecision,void 0),o.outputGeometryPrecisionUnits=validation.string("outputGeometryPrecisionUnits",i.outputGeometryPrecisionUnits,void 0),o.outputLines=validation.string("outputLines",i.outputLines,void 0),o.polygonBarriers=validation.exists("polygonBarriers",i.polygonBarriers,void 0),o.polylineBarriers=validation.exists("polylineBarriers",i.polylineBarriers,void 0),o.preserveFirstStop=validation.boolean("preserveFirstStop",i.preserveFirstStop,void 0),o.preserveLastStop=validation.boolean("preserveLastStop",i.preserveLastStop,void 0),o.restrictionAttributes=validation.exists("restrictionAttributes",i.restrictionAttributes,void 0),o.restrictUTurns=validation.string("restrictUTurns",i.restrictUTurns,void 0),o.returnBarriers=validation.boolean("returnBarriers",i.returnBarriers,void 0),o.returnDirections=validation.boolean("returnDirections",i.returnDirections,void 0),o.returnPolygonBarriers=validation.boolean("returnPolygonBarriers",i.returnPolygonBarriers,void 0),o.returnPolylineBarriers=validation.boolean("returnPolylineBarriers",i.returnPolylineBarriers,void 0),o.returnRoutes=validation.boolean("returnRoutes",i.returnRoutes,void 0),o.returnStops=validation.boolean("returnStops",i.returnStops,void 0),o.returnZ=validation.boolean("returnZ",i.returnZ,void 0),o.startTime=validation.exists("startTime",i.startTime,void 0),o.startTimeIsUTC=validation.boolean("startTimeIsUTC",i.startTimeIsUTC,void 0),o.useHierarchy=validation.boolean("useHierarchy",i.useHierarchy,void 0),o.useTimeWindows=validation.boolean("useTimeWindows",i.useTimeWindows,void 0);i=validation.exists("outSpatialReference",i.outSpatialReference,void 0);o.outSpatialReference=t.getOutSR(i);const s=new EsriRouteTask(r);r=isAbortable(e.cancellationToken)?{signal:e.cancellationToken.signal}:void 0,r=s.solve(o,r);return schedulePromiseCancellation(e,r),inline(r,function(i){return{barriers:i.barriers,messages:i.messages,polygonBarriers:i.polygonBarriers,polylineBarriers:i.polylineBarriers,routeResults:i.routeResults}})}};RouteTask.action="gcx:wf:arcgis::RouteTask",RouteTask.suite="gcx:wf:builtin",RouteTask=__decorate([activate(MapProvider)],RouteTask);export{RouteTask};