// 训练相关
import { request } from '@/utils/request'

// 获取列表
export const listApi = async () => {
  return await request({
    url: `/train/tasks`,
    method: 'GET'
  })
}

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

// 获取任务参数
export const taskParamsApi = async (taskId: string) => {
  return await request({
    url: `/train/${taskId}/params`,
    method: 'GET'
  })
}

// 获取训练详情
export const statusApi = async (taskId: string) => {
  return await request({
    url: `/train/${taskId}/status`,
    method: 'GET'
  })
}

// 获取训练日志
export const logsApi = async (taskId: string) => {
  return request({
    url: `/train/${taskId}/logs/stream`,
    method: 'GET',
    getRaw: true
  })
}

// 创建任务
export const createTaskApi = async (data: Record<string, any>) => {
  return await request({
    url: '/train/create',
    method: 'POST',
    data: data
  })
}

// 中断
export const onInterruptApi = async (taskId: string) => {
  return await request({
    url: `/train/${taskId}/stop`,
    method: 'POST'
  })
}

// 获取可导出的模型
export const getExportModelsApi = async (taskId: string) => {
  return await request({
    url: `/train/${taskId}/exports`,
    method: 'GET'
  })
}

// 模型导出
export const modelExportApi = async (data: Record<string, any>) => {
  return await request({
    url: `/train/${data.taskId}/export/${data.exportType}`,
    method: 'GET',
    getRaw: true
  })
}
