/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import{property as r,subclass as o}from"../../core/accessorSupport/decorators.js";import s from"../../geometry/Extent.js";import a from"../../geometry/Polyline.js";import n from"../../geometry/SpatialReference.js";import l from"./DirectionsFeature.js";import i from"./FeatureSet.js";import{reader as p}from"../../core/accessorSupport/decorators/reader.js";function u(e,t){if(0===e.length)return new a({spatialReference:t});const r=[];for(const a of e)for(const e of a.paths)r.push(...e);const o=[];r.forEach((e,t)=>{0!==t&&e[0]===r[t-1][0]&&e[1]===r[t-1][1]||o.push(e)});const{hasM:s,hasZ:n}=e[0];return new a({hasM:s,hasZ:n,paths:[o],spatialReference:t})}let m=class extends i{constructor(e){super(e),this.extent=null,this.features=[],this.geometryType="polyline",this.routeId=null,this.routeName=null,this.totalDriveTime=null,this.totalLength=null,this.totalTime=null}readFeatures(e,t){if(!e)return[];const r=t.summary.envelope.spatialReference??t.spatialReference,o=r&&n.fromJSON(r);return e.map(e=>{const t=l.fromJSON(e);if(null!=t.geometry&&(t.geometry.spatialReference=o),null!=t.events)for(const r of t.events)null!=r.geometry&&(r.geometry.spatialReference=o);return t})}get mergedGeometry(){if(!this.features)return null;return u(this.features.map(({geometry:e})=>e),this.extent.spatialReference)}get strings(){return this.features.flatMap(({strings:e})=>e).filter(t)}};e([r({type:s,json:{read:{source:"summary.envelope"}}})],m.prototype,"extent",void 0),e([r({nonNullable:!0})],m.prototype,"features",void 0),e([p("features")],m.prototype,"readFeatures",null),e([r()],m.prototype,"geometryType",void 0),e([r({readOnly:!0})],m.prototype,"mergedGeometry",null),e([r()],m.prototype,"routeId",void 0),e([r()],m.prototype,"routeName",void 0),e([r({value:null,readOnly:!0})],m.prototype,"strings",null),e([r({json:{read:{source:"summary.totalDriveTime"}}})],m.prototype,"totalDriveTime",void 0),e([r({json:{read:{source:"summary.totalLength"}}})],m.prototype,"totalLength",void 0),e([r({json:{read:{source:"summary.totalTime"}}})],m.prototype,"totalTime",void 0),m=e([o("esri.rest.support.DirectionsFeatureSet")],m);const f=m;export{f as default};
