import { request } from '@/utils/request/index.ts';


// 新增
export const addApi = async (data: Record<string, any>, controller?: AbortController) => {
  return await request({
    url: `/train/model/import`,
    method: 'POST',
    headers: {
      Accept: 'application/json',
      authorization: `Bearer ${localStorage.token}`
    },
    data: data,
    dataRaw: true,
  })
};

// 修改
export const updateApi = async (params: string, controller?: AbortController) => {
  return await request({
    url: `/train/model`,
    method: 'PUT',
    data: params
  })
};

// 删除
export const deleteApi = async (modelId: string) => {
  return await request({
    url: `/train/model/${modelId}`,
    method: 'DELETE',
  })
}

// 列表
export const listApi = async (params?: Record<string, any>) => {
  return await request({
    url: `/train/model/list`,
    method: 'GET',
    params: params
  })
}

// 给模型导入预训练权重
export const importPretrainedForModelApi = async (data: FormData) => {
  const modelId = data.get('modelId')
  return await request({
    url: `/train/model/${modelId}/pretrained_weights`,
    headers: {
      Accept: 'application/json',
      authorization: `Bearer ${localStorage.token}`
    },
    method: 'PUT',
    data: data,
    dataRaw: true,
  })
}

export const deletePretrainedForModelApi = async (data: Record<string, any>) => {
  return await request({
    url: `/train/model/${data.modelId}/pretrained_weights/${data.path}`,
    method: 'DELETE',
  })
}



