/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../request.js";import r from"../../core/Error.js";import{isAbortError as s}from"../../core/promiseUtils.js";import{isSupportedVersion as t,parseCapabilities as a}from"../raster/datasets/wcsCapabilitiesParser.js";import{parseCoverages as o}from"../raster/datasets/wcsCoverageParser.js";async function i(o,i){const{version:n,customParameters:c,signal:p}=i??{},l=n?.startsWith("1.0")?"version":"acceptVersions",m={service:"WCS",request:"GetCapabilities",[l]:n,...c};try{let{data:r}=await e(o,{query:m,responseType:"xml",signal:p});return i?.version||t(r)||(m[l]="2.0.1",({data:r}=await e(o,{query:m,responseType:"xml",signal:p}))),a(r)}catch(v){if(!s(v))throw new r("wcslayer:open","wcs capabilities is not valid or supported");throw v}}async function n(t,a){const{coverageIds:i,version:n,customParameters:c,signal:p}=a,l=n.slice(0,3),m="1.0"===l?"coverage":"1.1"===l?"identifiers":"coverageId",v={service:"WCS",request:"DescribeCoverage",version:n,[m]:i.join(","),...c};try{const{data:r}=await e(t,{query:v,responseType:"xml",signal:p});return o(r,n)}catch(w){if(!s(w))throw new r("wcslayer:open","wcs coverage description is not valid or supported");throw w}}export{n as describeCoverage,i as getCapabilities};
