/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import e from"../GraphApplyEditsResult.js";import{wasmErrorToEsriError as t}from"./wasmUtils.js";function r(r){const s=r.has_error(),_=new e({hasError:s,error:s?t(r.error):null}),d=r.get_edit_results_count();for(let e=0;e<d;e++){const s=r.get_edit_results_at(e);s.deleteLater();const d=r.get_edit_results_type_name_at(e),o=[],a=[],l=[],n=s.get_add_results_count(),c=s.get_update_results_count(),u=s.get_delete_results_count();for(let e=0;e<n;e++){const r=s.get_add_result_at(e);r.deleteLater(),o.push({id:r.id,error:t(r.error)})}for(let e=0;e<c;e++){const r=s.get_update_result_at(e);r.deleteLater(),a.push({id:r.id,error:t(r.error)})}for(let e=0;e<u;e++){const r=s.get_delete_result_at(e);r.deleteLater(),l.push({id:r.id,error:t(r.error)})}_.editResults.push({typeName:d,adds:o,updates:a,deletes:l})}const o=r.get_cascaded_rel_deletes_count();for(let e=0;e<o;e++){const s=r.get_cascaded_rel_deletes_at(e);s.deleteLater();const d=r.get_cascaded_rel_deletes_type_name_at(e),o=[];for(let e=0;e<s.get_count();e++){const r=s.get_result_at(e);r.deleteLater(),o.push({id:r.id,originId:r.origin_id,destinationId:r.dest_id,error:t(r.error)})}_.cascadeRelationshipDeleteResults.push({typeName:d,cascadeRelationshipDeletes:o})}if(r.has_cascading_provenance_deletes()){const e=r.get_cascading_provenance_deletes();e.deleteLater();const s=e.get_count();for(let r=0;r<s;r++){const s=e.get_result_at(r);s.deleteLater(),_.cascadeProvenanceDeleteResults.push({id:s.id,error:t(s.error)})}}return _}export{r as decoderToApplyEditsResponse};
