/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../chunks/_rollupPluginBabelHelpers","../request","../core/maybe","../geometry/support/normalizeUtils","./networkService","./utils","./route/utils","./support/RouteSolveResult"],(function(e,r,t,s,o,n,a,u,i){"use strict";function l(e){return"esri.rest.support.FeatureSet"===(null==e?void 0:e.declaredClass)}function c(e,r,t){return p.apply(this,arguments)}function p(){return(p=r._asyncToGenerator((function*(e,r,s){const i=[],c=[],p={},d={},y=a.parseUrl(e),{path:m}=y;l(r.stops)&&n.collectGeometries(r.stops.features,c,"stops.features",p),l(r.pointBarriers)&&n.collectGeometries(r.pointBarriers.features,c,"pointBarriers.features",p),l(r.polylineBarriers)&&n.collectGeometries(r.polylineBarriers.features,c,"polylineBarriers.features",p),l(r.polygonBarriers)&&n.collectGeometries(r.polygonBarriers.features,c,"polygonBarriers.features",p);const g=yield o.normalizeCentralMeridian(c);for(const t in p){const e=p[t];i.push(t),d[t]=g.slice(e[0],e[1])}if(n.isInputGeometryZAware(d,i)){let e=null;try{e=yield n.fetchServiceDescription(m,r.apiKey,s)}catch{}e&&!e.hasZ&&n.dropZValuesOffInputGeometry(d,i)}for(const t in d)d[t].forEach(((e,s)=>{r.get(t)[s].geometry=e}));const h={...s,query:{...y.query,...u.routeParametersToQueryParameters(r),f:"json"}},v=m.endsWith("/solve")?m:`${m}/solve`,{data:R}=yield t(v,h);return f(R)}))).apply(this,arguments)}function f(e){var r;const{barriers:t,directionLines:o,directionPoints:n,directions:a,messages:u,polygonBarriers:l,polylineBarriers:c,routes:p,stops:f,traversedEdges:d,traversedJunctions:y,traversedTurns:m}=e,g=e=>{const r=v.find((r=>r.routeName===e));if(s.isSome(r))return r;const t={routeId:v.length+1,routeName:e};return v.push(t),t},h=e=>{const r=v.find((r=>r.routeId===e));if(s.isSome(r))return r;const t={routeId:e,routeName:null};return v.push(t),t},v=[];null==p||p.features.forEach(((e,r)=>{e.geometry.spatialReference=p.spatialReference;const t=e.attributes.Name,s=r+1;v.push({routeId:s,routeName:t,route:e})})),null==a||a.forEach((e=>{const{routeName:r}=e;g(r).directions=e}));const R=null!=(r=null==f?void 0:f.features.every((e=>s.isNone(e.attributes.RouteName))))&&r&&v.length>0?v[0].routeName:null;return null==f||f.features.forEach((e=>{var r;e.geometry&&(null!=(r=e.geometry).spatialReference||(r.spatialReference=f.spatialReference));const t=null!=R?R:e.attributes.RouteName,s=g(t);null!=s.stops||(s.stops=[]),s.stops.push(e)})),null==o||o.features.forEach((e=>{const r=e.attributes.RouteID,t=h(r),{geometryType:s,spatialReference:n}=o;null!=t.directionLines||(t.directionLines={features:[],geometryType:s,spatialReference:n}),t.directionLines.features.push(e)})),null==n||n.features.forEach((e=>{const r=e.attributes.RouteID,t=h(r),{geometryType:s,spatialReference:o}=n;null!=t.directionPoints||(t.directionPoints={features:[],geometryType:s,spatialReference:o}),t.directionPoints.features.push(e)})),null==d||d.features.forEach((e=>{const r=e.attributes.RouteID,t=h(r),{geometryType:s,spatialReference:o}=d;null!=t.traversedEdges||(t.traversedEdges={features:[],geometryType:s,spatialReference:o}),t.traversedEdges.features.push(e)})),null==y||y.features.forEach((e=>{const r=e.attributes.RouteID,t=h(r),{geometryType:s,spatialReference:o}=y;null!=t.traversedJunctions||(t.traversedJunctions={features:[],geometryType:s,spatialReference:o}),t.traversedJunctions.features.push(e)})),null==m||m.features.forEach((e=>{const r=e.attributes.RouteID,t=h(r);null!=t.traversedTurns||(t.traversedTurns={features:[]}),t.traversedTurns.features.push(e)})),i.fromJSON({routeResults:v,barriers:t,polygonBarriers:l,polylineBarriers:c,messages:u})}e.solve=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
