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