import{lt as e,st as t}from"./index-Bo9BrBsx.js";const n={getAvailableModels:async()=>(await t.get(e.IMPORT_MODELS)).data,getFields:async n=>(await t.get(`${e.IMPORT_FIELDS}${n}/`)).data,downloadTemplate:async(n,r)=>{let i=r?.length?{fields:r.join(`,`)}:{},a=await t.get(`${e.IMPORT_TEMPLATE}${n}/`,{params:i,responseType:`blob`}),o=new Blob([a.data],{type:`text/csv`}),s=window.URL.createObjectURL(o),c=document.createElement(`a`);c.href=s,c.download=`${n.toLowerCase()}_import_template.csv`,document.body.appendChild(c),c.click(),document.body.removeChild(c),window.URL.revokeObjectURL(s)},validateFile:async(n,r)=>{let i=new FormData;i.append(`import_file`,r),i.append(`model_name`,n),i.append(`input_format`,`0`);let{request_id:a}=(await t.post(e.IMPORT_VALIDATE,i,{headers:{"Content-Type":`multipart/form-data`}})).data,o=0;for(;o<240;){await new Promise(e=>setTimeout(e,500));let n=await t.post(`${e.IMPORT_STATUS}${a}/`);if(n.data.status===!0)return n.data.message;if(n.data.failed===!0){let e=n.data.message||`Validation failed`;throw Error(typeof e==`string`?e:`Validation failed`)}o++}throw Error(`Validation timed out. Please try again.`)},executeImport:async(n,r)=>{let i=new FormData;i.append(`model_name`,n),i.append(`import_file_name`,r.import_file_name),i.append(`original_file_name`,r.original_file_name),i.append(`input_format`,String(r.input_format));let{request_id:a}=(await t.post(e.IMPORT_EXECUTE,i,{headers:{"Content-Type":`multipart/form-data`}})).data,o=0;for(;o<600;){await new Promise(e=>setTimeout(e,500));let n=await t.post(`${e.IMPORT_STATUS}${a}/`);if(n.data.status===!0)return n.data.message;if(n.data.failed===!0){let e=n.data.message||`Import failed`;throw Error(typeof e==`string`?e:`Import failed`)}o++}throw Error(`Import timed out. Please try again.`)},checkStatus:async n=>(await t.get(`${e.IMPORT_STATUS}${n}/`)).data,getHistory:async(n=1,r=20)=>(await t.get(e.IMPORT_HISTORY,{params:{page:n,page_size:r}})).data,getHistoryDetail:async n=>(await t.get(`${e.IMPORT_HISTORY}${n}/`)).data};export{n as t};