import e from"@arcgis/core/geometry/Multipoint";import r from"@arcgis/core/geometry/Point";import t from"@arcgis/core/geometry/Polygon";import o from"@arcgis/core/geometry/Polyline";import i from"@arcgis/core/geometry/SpatialReference";import{ArgumentError as n}from"../ArgumentError.js";import{checkArg as s}from"./checkArg.js";import{isExtent as a,isMultipoint as c,isPoint as m,isPolygon as y,isPolyline as g}from"./esri.js";export function esriToGeoJSON(e){if(s("geometry",e).isNotMissing(),m(e)){const{x:r,y:t}=e;return{type:"Point",coordinates:[r,t]}}if(c(e))return{type:"MultiPoint",coordinates:e.points};if(g(e))return e.paths.length>1?{type:"MultiLineString",coordinates:e.paths}:{type:"LineString",coordinates:e.paths[0]};if(y(e))return{type:"Polygon",coordinates:e.rings};if(a(e)){const r=[e.xmin,e.ymax];return{type:"Polygon",coordinates:[[r,[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin],r]]}}throw new n("Cannot determine what type of WKT geometry to create")}export function geoJSONToEsri(a){switch(s("geometry",a).isNotMissing(),s("geometry.type",a.type).isNotMissing(),a.type){case"Point":return s("geometry.coordinates",a.coordinates).satisfies(u),new r({x:a.coordinates[0],y:a.coordinates[1],spatialReference:i.WGS84});case"MultiPoint":return s("geometry.coordinates",a.coordinates).satisfies(d),new e({points:a.coordinates,spatialReference:i.WGS84});case"LineString":return s("geometry.coordinates",a.coordinates).satisfies(d),new o({paths:[a.coordinates],spatialReference:i.WGS84});case"MultiLineString":return s("geometry.coordinates",a.coordinates).satisfies(p),new o({paths:a.coordinates,spatialReference:i.WGS84});case"Polygon":return s("geometry.coordinates",a.coordinates).satisfies(p),new t({rings:a.coordinates,spatialReference:i.WGS84});case"MultiPolygon":return s("geometry.coordinates",a.coordinates).satisfies(f),new t({rings:a.coordinates.flat(),spatialReference:i.WGS84})}throw new n("Cannot determine what type of esri geometry to create")}function p(e){return!!Array.isArray(e)&&!e.some((e=>!d(e)))}function f(e){return!!Array.isArray(e)&&!e.some((e=>!p(e)))}function u(e){return!!Array.isArray(e)&&!e.some((e=>"number"!=typeof e))}function d(e){return!!Array.isArray(e)&&!e.some((e=>!u(e)))}