// 推理任务相关
import { request } from '@/utils/request'

// 获取推理任务列表
export const listApi = async () => {
  return await request({
    url: '/inference/tasks',
    method: 'GET'
  })
}

// 删除任务
export const deleteApi = async (taskId: string) => {
  return await request({
    url: `/inference/tasks/${taskId}`,
    method: 'DELETE',
  })
}

// 获取推理任务结果
export const taskResultApi = async (taskId: string, controller?: AbortController) => {
  return await request({
    url: `/inference/results/${taskId}`,
    method: 'GET',
    controller: controller,
  })
}

// 获取推理任务状态
export const taskStatusApi = async (taskId: string, controller?: AbortController) => {
  return await request({
    url: `/inference/status/${taskId}`,
    method: 'GET',
    controller: controller,
  })
}

// 启动推理任务
export const createTaskApi = async (data: Record<string, any>, controller?: AbortController) => {
  return await request({
    url: '/inference/run',
    method: 'POST',
    data: data,
    controller: controller,
  })
}


// 获取推理任务模式
export const optionsApi = async () => {
  return await request({
    url: '/inference/infer_types',
    method: 'GET',
  })
}

// 获取权重目录
export const weightOptionsApi = async (params: Record<string, any>) => {
  return await request({
    url: '/inference/directories',
    method: 'GET',
    params: params
  })
}

// 获取推理任务日志
export const logsApi = async (taskId: string, controller?: AbortController) => {
  return await request({
    url: `/inference/${taskId}/logs/stream`,
    method: 'GET',
    controller: controller,
    getRaw: true
  })
}

// 停止推理任务
export const stopTaskApi = async (taskId: string, controller?: AbortController) => {
  return await request({
    url: `/inference/${taskId}/stop`,
    method: 'POST',
    controller: controller,
  })
}

