/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../../core/Error.js";import t from"../../../geometry/Geometry.js";import n from"../../../geometry/Multipoint.js";import o from"../../../geometry/Point.js";import r from"../../../geometry/Polygon.js";import a from"../../../geometry/Polyline.js";import{WasmProvenanceBehaviorValues as i}from"./WasmQueryWrapperInterfaces.js";function l(e,t){const n=new t.ArrayValue;return n.deleteLater(),e.forEach(e=>{n.add_value(f(e,t))}),n}function s(e,t){const n=new t.ObjectValue;n.deleteLater();for(const[o,r]of Object.entries(e))n.set_key_value(o,f(r,t));return n}function u(t,i){if(t instanceof n)return g(t,i);if(t instanceof o)return h(t,i);if(t instanceof a||t instanceof r)return p(t,i);throw new e("knowledge-graph:unsupported-geometry","Only Point, Multipoint, Polyline, and Polygon geometry are supported by ArcGIS Knowledge",{geometry:t})}function y(e,t){t.input_quantization_parameters={xy_resolution:e.xyResolution,x_false_origin:e.xFalseOrigin,y_false_origin:e.yFalseOrigin,z_resolution:e.zResolution,z_false_origin:e.zFalseOrigin,m_resolution:e.mResolution,m_false_origin:e.mFalseOrigin}}function m(t,n,o){if(!t.extent)throw new e("knowledge-graph:illegal-output-quantization","The Output quantization provided to the encoder had an illegal value as part of its extent",t.extent);if(!t.quantizeMode)throw new e("knowledge-graph:illegal-output-quantization","The Output quantization contained an illegal mode setting",t.quantizeMode);if(!t.tolerance)throw new e("knowledge-graph:illegal-output-quantization","The Output quantization contained an illegal tolerance setting",t.quantizeMode);n.output_quantization_parameters={extent:{xmax:t.extent.xmax,ymax:t.extent.ymax,xmin:t.extent.xmin,ymin:t.extent.ymin},quantize_mode:o.esriQuantizeMode[t.quantizeMode],tolerance:t.tolerance}}function c(e,t){t.provenance_behavior={value:i[e]}}function f(e,n){if(null==e)return"";if("object"!=typeof e)return e;if(e instanceof Date)return e;if(e instanceof t)return u(e,n);if(Array.isArray(e)){const t=new n.ArrayValue;return t.deleteLater(),e.forEach(e=>{t.add_value(f(e,n))}),t}return s(e,n)}function p(e,t){const n=new t.GeometryValue;n.deleteLater(),n.has_z=e.hasZ,n.has_m=e.hasM;const o=[],i=[];let l=[];e instanceof a?(n.geometry_type=t.esriGeometryType.esriGeometryPolyline,l=e.paths):e instanceof r&&(n.geometry_type=t.esriGeometryType.esriGeometryPolygon,l=e.rings);let s=0,u=0;return l.forEach(e=>{let t=0;e.forEach(e=>{t++,e.forEach(e=>{o[u]=e,u++})}),i[s]=t,s++}),n.coords=new Float64Array(o),n.lengths=new Uint32Array(i),n}function g(e,t){const n=new t.GeometryValue;n.deleteLater(),n.geometry_type=n.geometry_type=t.esriGeometryType.esriGeometryMultipoint,n.has_z=e.hasZ,n.has_m=e.hasM;const o=[],r=[];r[0]=e.points.length;let a=0;return e.points.forEach(e=>{e.forEach(e=>{o[a]=e,a++})}),n.coords=new Float64Array(o),n.lengths=new Uint32Array(r),n}function h(e,t){const n=new t.GeometryValue;n.deleteLater(),n.geometry_type=t.esriGeometryType.esriGeometryPoint,n.has_z=e.hasZ,n.has_m=e.hasM;const o=[],r=[];r[0]=1,o[0]=e.x,o[1]=e.y;let a=2;return e.hasZ&&(o[a]=e.z,a++),e.hasM&&(o[a]=e.m,a++),n.coords=new Float64Array(o),n.lengths=new Uint32Array(r),n}export{l as bindParamArrayToWasm,s as bindParamObjectToWasm,f as convertRecursiveBindParam,u as geometryToWasm,y as setInputQuantizationParametersOnEncoder,m as setOutputQuantizationParametersOnEncoder,c as setProvenanceBehaviorOnEncoder};
