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 AddAttachment{execute(t,e){var i=validation.urlOrLayer(t,isArcGisApiVersion3x).trim(),n=validation.number("objectId",t.objectId,validation.never),r=validation.exists("attachmentIds",t.attachment,validation.never),t=validation.number("timeout",t.timeout,void 0),n=addToPath(i,`${n}/addAttachment`);const o=new FormData;o.append("attachment",r),o.append("f","json");let a;if(isArcGisApiVersion3x){r={url:n,form:o,handleAs:"json",timeout:t};a=esriRequest(r,{usePost:!0})}else{const s={method:"post",body:o,responseType:"json",timeout:t,cacheBust:!1};isAbortable(e.cancellationToken)&&(s.signal=e.cancellationToken.signal),a=esriRequest(n,s).then(t=>t.data)}return schedulePromiseCancellation(e,a),inline(a,function(t){t=t.addAttachmentResult;if(!t)throw new GenericActivityError('Error running the "Add Attachment" activity. The response did not include the required "addAttachmentResult" property.');return{result:t}})}}AddAttachment.action="gcx:wf:arcgis::AddAttachment",AddAttachment.suite="gcx:wf:builtin";export{AddAttachment};