/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import e from"../../../core/Logger.js";import t from"../../../geometry/SpatialReference.js";import n from"../Entity.js";import r from"../GraphObject.js";import o from"../GraphQueryResultHeader.js";import s from"../ObjectValue.js";import u from"../Path.js";import a from"../Relationship.js";import{wasmToPolygonGeometry as i,wasmToPolylineGeometry as c,wasmToMultipointGeometry as l,wasmToPointGeometry as p}from"./wasmToGeometryFactories.js";const d=()=>e.getLogger("esri.rest.knowledgeGraph.WasmToQueryResponseObjConstructors"),_={decodedWasmObjToQueryResponseObj:(e,t,n)=>{if(null==e)return null;if("object"!=typeof e)return e;if("getDate"in e)return e;if("geometry_type"in e)switch(e.geometry_type.value){case null:return null;case 1:return p(e,n);case 2:return l(e,n);case 3:return c(e,n);case 4:return i(e,n);case 5:case 7:return d().warnOnce("Envelope and Multipatch are not supported on knowledge entities, but one of those geometry types was detected. Result interpreted as null"),null;default:return d().warnOnce("Unknown or blank geometry type returned - Result interpreted as null"),null}else{if(!("object_value_type"in e))return d().warnOnce("A decoded value came back of a type that is not supported. Result interpreted as null"),null;switch(e.object_value_type.value){case 0:return h(e,t,n);case 1:return y(e,t,n);case 2:return b(e,t,n);case 3:return w(e,t,n);case 4:return f(e,t,n);default:return d().warnOnce("Unknown graph object type detected!  Result interpreted as null"),null}}}};function f(e,t,n){const r=[],o=e.count();for(let s=0;s<o;s++){const o=e.get_value_at(s);r.push(m(o,t,n))}return r}function m(e,t,n){return _.decodedWasmObjToQueryResponseObj(e,t,n)}function y(e,t,r){const o=e.type_name,s=j(e,t,r),u=e.get_id();return new n(Object.assign({typeName:o,id:u},s))}function g(e,t,n){return new r(j(e,t,n))}function j(e,t,n){const r={},o=e.key_count();for(let s=0;s<o;s++)r[e.get_key_at(s)]=m(e.get_value_at(s),t,n);return{properties:r}}function h(e,t,n){return new s(j(e,t,n))}function w(e,t,n){const r=e.entity_count(),o=e.relationship_count(),s=[];for(let u=0;u<r;u++)s.push(y(e.get_entity_at(u),t,n)),u<o&&s.push(b(e.get_relationship_at(u),t,n));return new u({path:s})}function b(e,t,n){const r=e.type_name,o=j(e,t,n);return new a(Object.assign({typeName:r,id:e.get_id(),originId:e.get_origin_entity_id(),destinationId:e.get_destination_entity_id()},o))}function O(e){const n=[];for(let t=0;t<e.get_header_keys().size();t++)n.push(e.get_header_keys().get(t));const r=new t(e.get_out_sr());return new o({headerKeys:n,outSpatialReference:r,exceededTransferLimit:e.exceeded_transfer_limit()})}export{_ as decodeWasmObjectTest,m as decodedWasmObjToQueryResponseObj,f as wasmArrayToArray,y as wasmToEntity,g as wasmToGraphObject,O as wasmToGraphQueryResponseHeader,h as wasmToObjectValue,w as wasmToPath,b as wasmToRelationship};
