/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{sqlAnd as e}from"../../../core/sql.js";import r from"../../../geometry/Point.js";import{polygonCentroidPoint as t}from"../../../geometry/support/centroid.js";import{searchImages as n}from"../../../layers/orientedImagery/queries.js";import{createCoveragePolygon as o}from"../../../layers/orientedImagery/core/coverageUtils.js";async function i(e,i,s,c){const{polygon:a}=o(i.attributes),u=r.fromJSON(t(a));u.z=void 0;const d=p(e.definitionExpression,s);let y,l;try{y=await n({layerInstanceOrURL:e,point:u,queryParams:{where:d}},c)}catch(m){l=m}return new f(u,y,l)}async function s(e,r,t,o){const i=e.sequenceOrderField??"SequenceOrder",s=p(e.definitionExpression,t,`${i} IS NOT NULL`);let c,a;try{c=await n({layerInstanceOrURL:e,point:r,queryParams:{where:s,orderByFields:[`${i}`],returnGeometry:!0,outFields:["*"]}},o)}catch(u){a=u}return new f(r,c,a)}function c(e,r,t){const n=e.sequenceOrderField,o=p(e.definitionExpression,r,`${n} IS NOT NULL`);return e.queryFeatureCount({where:o},t)}async function a(r,t,n,o="ASC",i,s){const c=r.sequenceOrderField??"SequenceOrder";let a=p(r.definitionExpression,i,`${c} IS NOT NULL`);const u="number"==typeof t?t-1:void 0;"string"===t&&(a=e(a,`${c} = ${t}`));try{const e=await r.queryFeatures({where:a,returnGeometry:!0,orderByFields:[`${c} ${o}`],outFields:["*"],start:u,num:n},s);return await w(e,r),new y(e)}catch(d){return new y(void 0,d)}}async function u(e,r,t=0,n=1,o,i){const s=e.sequenceOrderField??"SequenceOrder",c=m(s,t),a=p(e.definitionExpression,o,l(t,r,s));try{const r=await e.queryFeatures({where:a,orderByFields:c,num:n,outFields:["*"],returnGeometry:!0},i);return await w(r,e),new y(r)}catch(u){return new y(void 0,u)}}async function d(e,r,t,n){const o=Array.isArray(r)?r:[r],i=p(e.definitionExpression,t,`${e.objectIdField} IN (${o.join(",")})`);try{const r=await e.queryFeatures({where:i,outFields:["*"],returnGeometry:!0},n);return await w(r,e),new y(r)}catch(s){return new y(void 0,s)}}class y{constructor(e,r){this.response=e,this.error=r}}class f{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 p(...r){let t="1=1";return r.forEach(r=>{t=e(t,r)}),t}export{f as QueryNextLocationFeaturesResponse,y as QueryOrientedImageryFeaturesResponse,u as queryAfterSequenceField,d as queryFeatureByObjectIds,i as queryNextLocationFeatures,a as queryOffsetSequenceFeatures,c as querySequenceCount,s as querySequenceFeaturesAroundPoint};
