/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/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 a from"../ObjectValue.js";import u from"../Path.js";import s 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");function m(e){return null!=e&&"object"==typeof e&&"object_value_type"in e}function f(e,t){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,t);case 2:return l(e,t);case 3:return c(e,t);case 4:return i(e,t);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}return d().warnOnce("A decoded value came back of a type that is not supported. Result interpreted as null"),null}const _={decodedWasmObjToQueryResponseObj:(e,t,n)=>{if(!m(e))return f(e,n);if(t)switch(e.object_value_type.value){case 0:return b(e,t,n);case 1:return j(e,t,n);case 2:return R(e,t,n);case 3:return O(e,t,n);case 4:return y(e,t,n);default:return d().warnOnce("Unknown graph object type detected!  Result interpreted as null"),null}return d().warnOnce("A decoded value came back of a type that is not supported. Result interpreted as null"),null}};function y(e,t,n){const r=[],o=e.count();for(let a=0;a<o;a++){const o=e.get_value_at(a);r.push(g(o,t,n))}return r}function g(e,t,n){return _.decodedWasmObjToQueryResponseObj(e,t,n)}function j(e,t,r){const o=e.type_name,a=w(e,t,r),u=e.get_id();return new n(Object.assign({typeName:o,id:u},a))}function h(e,t,n){return new r(w(e,t,n))}function w(e,t,n){const r={},o=e.key_count();for(let a=0;a<o;a++)r[e.get_key_at(a)]=g(e.get_value_at(a),t,n);return{properties:r}}function b(e,t,n){return new a(w(e,t,n))}function O(e,t,n){const r=e.entity_count(),o=e.relationship_count(),a=[];for(let u=0;u<r;u++)a.push(j(e.get_entity_at(u),t,n)),u<o&&a.push(R(e.get_relationship_at(u),t,n));return new u({path:a})}function R(e,t,n){const r=e.type_name,o=w(e,t,n);return new s(Object.assign({typeName:r,id:e.get_id(),originId:e.get_origin_entity_id(),destinationId:e.get_destination_entity_id()},o))}function k(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(),dataModelTimestamp:e.data_model_timestamp?new Date(e.data_model_timestamp):null})}export{_ as decodeWasmObjectTest,f as decodedWasmNonGraphObjToQueryResponseObj,g as decodedWasmObjToQueryResponseObj,y as wasmArrayToArray,j as wasmToEntity,h as wasmToGraphObject,k as wasmToGraphQueryResponseHeader,b as wasmToObjectValue,O as wasmToPath,R as wasmToRelationship};
