import{GenericActivityError}from"../../Errors.js";import{validation}from"../../Validation.js";import{addToPath,inline,isAbortable,schedulePromiseCancellation}from"./tools.js";import{isArcGisApiVersion3x}from"./ArcGisApiVersion.js";import esriRequest from"@arcgis/core/request";class UpdateAttachment{execute(t,e){var a=validation.urlOrLayer(t,isArcGisApiVersion3x).trim(),i=validation.number("objectId",t.objectId,validation.never);const n=validation.number("attachmentId",t.attachmentId,validation.never);var r=validation.exists("attachment",t.attachment,validation.never),o=validation.string("gdbVersion",t.gdbVersion),s=validation.boolean("returnEditMoment",t.returnEditMoment,!1),d=validation.number("uploadId",t.uploadId),c=validation.number("timeout",t.timeout),i=addToPath(a,`${i}/updateAttachment`);let l=validation.string("attachmentName",t.attachmentName,"").trim();""===l&&(l=void 0);const m=new FormData;m.append("f","json"),m.append("attachmentId",n.toString()),m.append("attachment",r,l),o&&m.append("gdbVersion",o),m.append("returnEditMoment",s?"true":"false"),null!=d&&m.append("uploadId",d?"true":"false");let u;if(isArcGisApiVersion3x){d={url:i,form:m,handleAs:"json",timeout:c};u=esriRequest(d,{usePost:!0})}else{const p={method:"post",body:m,responseType:"json",timeout:c,cacheBust:!1};isAbortable(e.cancellationToken)&&(p.signal=e.cancellationToken.signal),u=esriRequest(i,p).then(t=>t.data)}return schedulePromiseCancellation(e,u),inline(u,function(t){t=t.updateAttachmentResult;if(!t)throw new GenericActivityError('Error running the "Update Attachment" activity. The response did not include the required "updateAttachmentResult" property.');return{result:t}})}}UpdateAttachment.action="gcx:wf:arcgis::UpdateAttachment",UpdateAttachment.suite="gcx:wf:builtin";export{UpdateAttachment};