/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{sqlAnd as e}from"../../../core/sql.js";import r from"../../../geometry/Point.js";import t from"../../../geometry/SpatialReference.js";import{polygonCentroidPoint as n}from"../../../geometry/support/centroid.js";import{searchImages as o}from"../../../layers/orientedImagery/queries.js";import{createCoveragePolygon as i}from"../../../layers/orientedImagery/core/coverageUtils.js";async function s(e,t,s,a){const{polygon:c}=i(t.attributes),u=r.fromJSON(n(c));u.z=void 0;const y=h(e.definitionExpression,s);let d,f;try{d=await o({layerInstanceOrURL:e,point:u,queryParams:{where:y}},a)}catch(l){f=l}return new p(u,d,f)}async function a(e,r,t,n){const i=e.sequenceOrderField??"SequenceOrder",s=h(e.definitionExpression,t,`${i} IS NOT NULL`);let a,c;try{a=await o({layerInstanceOrURL:e,point:r,queryParams:{where:s,orderByFields:[`${i}`],returnGeometry:!0,outFields:["*"]}},n)}catch(u){c=u}return new p(r,a,c)}function c(e,r,t){const n=e.sequenceOrderField,o=h(e.definitionExpression,r,`${n} IS NOT NULL`),i=e.createQuery();return i.where=o,e.queryFeatureCount(i,t)}async function u(r,n,o,i="ASC",s,a){const c=r.sequenceOrderField??"SequenceOrder";let u=h(r.definitionExpression,s,`${c} IS NOT NULL`);const y="number"==typeof n?n-1:void 0;"string"===n&&(u=e(u,`${c} = ${n}`));const d=r.createQuery();d.where=u,d.start=y,d.num=o,d.orderByFields=[`${c} ${i}`],r.spatialReference.isGeographic&&(d.outSpatialReference=t.WebMercator);try{const e=await r.queryFeatures(d,a);return await w(e,r),new f(e)}catch(p){return new f(void 0,p)}}async function y(e,r,n=0,o=1,i,s){const a=e.sequenceOrderField??"SequenceOrder",c=m(a,n),u=h(e.definitionExpression,i,l(n,r,a)),y=e.createQuery();y.where=u,y.num=o,y.orderByFields=c,e.spatialReference.isGeographic&&(y.outSpatialReference=t.WebMercator);try{const r=await e.queryFeatures(y,s);return await w(r,e),new f(r)}catch(d){return new f(void 0,d)}}async function d(e,r,n,o){const i=Array.isArray(r)?r:[r],s=h(e.definitionExpression,n,`${e.objectIdField} IN (${i.join(",")})`),a=e.createQuery();a.where=s,e.spatialReference.isGeographic&&(a.outSpatialReference=t.WebMercator);try{const r=await e.queryFeatures(a,o);return await w(r,e),new f(r)}catch(c){return new f(void 0,c)}}class f{constructor(e,r){this.response=e,this.error=r}}class p{constructor(e,r,t){this.nextLocation=e,this.response=r,this.error=t}}function l(e,r,t){return e>0?`${t} IS NOT NULL AND ${t} > ${r}`:`${t} IS NOT NULL AND ${t} < ${r}`}function m(e,r){return r>0?[`${e}`]:[`${e} DESC`]}async function w(e,r){const t=await import("../../../layers/orientedImagery/core/ExposurePoint.js").then(e=>e.default);e.features.forEach(e=>{const n=t.fromJSON({...e.toJSON(),layer:r});n&&(e.attributes=n)})}function h(...r){let t="1=1";return r.forEach(r=>{t=e(t,r)}),t}export{p as QueryNextLocationFeaturesResponse,f as QueryOrientedImageryFeaturesResponse,y as queryAfterSequenceField,d as queryFeatureByObjectIds,s as queryNextLocationFeatures,u as queryOffsetSequenceFeatures,c as querySequenceCount,a as querySequenceFeaturesAroundPoint};
