import{__decorate}from"tslib";import ClosestFacilityParameters from"@arcgis/core/tasks/support/ClosestFacilityParameters";import{validation}from"../../Validation.js";import{inline,isAbortable,schedulePromiseCancellation}from"./tools.js";import{MapProvider}from"./MapProvider.js";import{activate}from"../../Hooks.js";import EsriClosestFacilityTask from"@arcgis/core/tasks/ClosestFacilityTask";let ClosestFacilityTask=class{execute(i,t,e){var r=validation.string("url",i.url,validation.never);const a=new ClosestFacilityParameters;a.facilities=validation.exists("facilities",i.facilities),a.incidents=validation.exists("incidents",i.incidents),a.accumulateAttributes=validation.array("accumulateAttributes",i.accumulateAttributes,void 0),a.attributeParameterValues=validation.exists("attributeParameterValues",i.attributeParameterValues,void 0),a.defaultCutoff=validation.number("defaultCutoff",i.defaultCutoff,void 0),a.defaultTargetFacilityCount=validation.number("defaultTargetFacilityCount",i.defaultTargetFacilityCount,void 0),a.directionsLanguage=validation.string("directionsLanguage",i.directionsLanguage,void 0),a.directionsLengthUnits=validation.string("directionsLengthUnits",i.directionsLengthUnits,void 0),a.directionsOutputType=validation.string("directionsOutputType",i.directionsOutputType,void 0),a.directionsStyleName=validation.string("directionsStyleName",i.directionsStyleName,void 0),a.directionsTimeAttribute=validation.string("directionsTimeAttribute",i.directionsTimeAttribute,void 0),a.doNotLocateOnRestrictedElements=validation.boolean("doNotLocateOnRestrictedElements",i.doNotLocateOnRestrictedElements,void 0),a.impedanceAttribute=validation.string("impedanceAttribute",i.impedanceAttribute,void 0),a.impedanceAttribute||(a.impedanceAttribute=validation.string("impedenceAttribute",i.impedenceAttribute,void 0)),a.outputGeometryPrecision=validation.number("outputGeometryPrecision",i.outputGeometryPrecision,void 0),a.outputGeometryPrecisionUnits=validation.string("outputGeometryPrecisionUnits",i.outputGeometryPrecisionUnits,void 0),a.outputLines=validation.string("outputLines",i.outputLines,void 0),a.pointBarriers=validation.exists("pointBarriers",i.pointBarriers,void 0),a.polygonBarriers=validation.exists("polygonBarriers",i.polygonBarriers,void 0),a.polylineBarriers=validation.exists("polylineBarriers",i.polylineBarriers,void 0),a.restrictionAttributes=validation.exists("restrictionAttributes",i.restrictionAttributes,void 0),a.restrictUTurns=validation.string("restrictUTurns",i.restrictUTurns,void 0),a.returnDirections=validation.boolean("returnDirections",i.returnDirections,void 0),a.returnFacilities=validation.boolean("returnFacilities",i.returnFacilities,void 0),a.returnIncidents=validation.boolean("returnIncidents",i.returnIncidents,void 0),a.returnPointBarriers=validation.boolean("returnPointBarriers",i.returnPointBarriers,void 0),a.returnPolygonBarriers=validation.boolean("returnPolygonBarriers",i.returnPolygonBarriers,void 0),a.returnPolylineBarriers=validation.boolean("returnPolylineBarriers",i.returnPolylineBarriers,void 0),a.returnRoutes=validation.boolean("returnRoutes",i.returnRoutes,!0),a.timeOfDay=validation.exists("timeOfDay",i.timeOfDay,void 0),a.timeOfDayUsage=validation.string("timeOfDayUsage",i.timeOfDayUsage,void 0),a.travelDirection=validation.string("travelDirection",i.travelDirection,void 0),a.useHierarchy=validation.boolean("useHierarchy",i.useHierarchy,void 0);i=validation.exists("outSpatialReference",i.outSpatialReference,void 0);a.outSpatialReference=e.getOutSR(i);const o=new EsriClosestFacilityTask(r);r=isAbortable(t.cancellationToken)?{signal:t.cancellationToken.signal}:void 0,r=o.solve(a,r);return schedulePromiseCancellation(t,r),inline(r,function(i){return{directions:i.directions,facilities:i.facilities,incidents:i.incidents,messages:i.messages,pointBarriers:i.pointBarriers,polygonBarriers:i.polygonBarriers,polylineBarriers:i.polylineBarriers,routes:i.routes}})}};ClosestFacilityTask.action="gcx:wf:arcgis::ClosestFacilityTask",ClosestFacilityTask.suite="gcx:wf:builtin",ClosestFacilityTask=__decorate([activate(MapProvider)],ClosestFacilityTask);export{ClosestFacilityTask};