/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../../request.js";import{srToRESTValue as t}from"../../../geometry/support/spatialReferenceUtils.js";import{mapParameters as o}from"../../operations/urlUtils.js";function r(e,o){const r=e.toJSON();return r.objectIds&&(r.objectIds=r.objectIds.join(",")),r.orderByFields&&(r.orderByFields=r.orderByFields.join(",")),r.outFields&&!o?.returnCountOnly?r.outFields.includes("*")?r.outFields="*":r.outFields=r.outFields.join(","):delete r.outFields,r.outSR&&(r.outSR=t(r.outSR)),r.dynamicDataSource&&(r.layer=JSON.stringify({source:r.dynamicDataSource}),delete r.dynamicDataSource),r}async function s(e,t,o){const r=await a(e,t,o),s=r.data,n=s.geometryType,d=s.spatialReference,c={};for(const a of s.relatedRecordGroups){const e={fields:void 0,geometryType:n,spatialReference:d,hasZ:!!s.hasZ,hasM:!!s.hasM,features:a.relatedRecords};if(null!=a.objectId)c[a.objectId]=e;else for(const t of Object.keys(a))"relatedRecords"!==t&&(c[a[t]]=e)}return{...r,data:c}}async function n(e,t,o){const r=await a(e,t,o,{returnCountOnly:!0}),s=r.data,n={};for(const a of s.relatedRecordGroups)null!=a.objectId&&(n[a.objectId]=a.count);return{...r,data:n}}async function a(t,s,n={},a){const d=o({...t.query,f:"json",...a,...r(s,a)});return e(t.path+"/queryRelatedRecords",{...n,query:{...n.query,...d}})}export{s as executeRelationshipQuery,n as executeRelationshipQueryForCount,r as toQueryStringParameters};
