/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import r from"../request.js";import{get as e}from"../core/accessorSupport/get.js";import{normalizeCentralMeridian as t}from"../geometry/support/normalizeUtils.js";import{collectGeometries as o,isInputGeometryZAware as s,fetchServiceDescription as i,dropZValuesOffInputGeometry as a}from"./networkService.js";import{parseUrl as n}from"./utils.js";import{serviceAreaParametersToQueryParameters as p}from"./route/utils.js";import f from"./support/FeatureSet.js";import u from"./support/ServiceAreaSolveResult.js";function c(r){return r instanceof f}async function l(f,l,m){const y=[],j=[],B={},S={},g=n(f),{path:h}=g;c(l.facilities)&&o(l.facilities.features,j,"facilities.features",B),c(l.pointBarriers)&&o(l.pointBarriers.features,j,"pointBarriers.features",B),c(l.polylineBarriers)&&o(l.polylineBarriers.features,j,"polylineBarriers.features",B),c(l.polygonBarriers)&&o(l.polygonBarriers.features,j,"polygonBarriers.features",B);const v=await t(j);for(const r in B){const e=B[r];y.push(r),S[r]=v.slice(e[0],e[1])}if(s(S,y)){let r=null;try{r=await i(h,l.apiKey,m)}catch{}r&&!r.hasZ&&a(S,y)}for(const r in S)S[r].forEach((t,o)=>{e(l,r)[o].geometry=t});const w={...m,query:{...g.query,...p(l),f:"json"}},{data:q}=await r(`${h}/solveServiceArea`,w);return u.fromJSON(q)}export{l as solve};
