import request from "@/utils/request";

//获取模型列表
const list=(data)=>{
    return request({
        url: `/models`,
        method: "get",
        params:data
      });
}

//创建模型
const add=(data)=>{ 
    return request({
        url: `/models`,
        method: "post",
        data:data
      });
}

//创建模型
const deleteModel=(id)=>{
    return request({
        url: `/models/${id}`,
        method: "delete"
      });
}

//获取模型详细信息
const findOne=(id)=>{
    return request({
        url: `/models/${id}`,
        method: "get"
      });
}
//获取模型适配的算子信息
const adaptOperators=(id)=>{
    return request({
        url: `/models/${id}/adapt_operators`,
        method: "get"
      });
}
//请求下载模型文件
const download=(id)=>{
    return request({
        url: `/models/${id}/download`,
        method: "get"
      });
}
//上传数据文件
const upload = (file) => {
    const formData = new FormData();
    formData.append("file_name", file.name);
    formData.append("file_content",file)
     formData.append("file",file)
    return request({
        url: `/models/upload`,
        method: "post",
        data: formData,
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
}
const updateModel=(data)=>{
    return request({
        url: `/models/${data.id}/files`,
        method: "put",
        data:{
            file_name:data.fileName,
            modl_file_type:data.fileType
        }
      });
}
export default {
    list,
    add,
    deleteModel,
    findOne,
    adaptOperators,
    download,
    upload,
    updateModel
}