import type * as T from './type'
import http from '@/utils/http'

const BASE_URL = '/project/task'

/** @desc 查询任务组列表 */
export function listTaskGroup(projectId: number) {
  return http.get(`${BASE_URL}/group`, { projectId })
}

/** @desc 新增任务组 */
export function addTaskGroup(data: any) {
  return http.post(`${BASE_URL}/group`, data)
}

/** @desc 修改任务组 */
export function updateTaskGroup(data: any, id: number) {
  return http.put(`${BASE_URL}/group/${id}`, data)
}

/** @desc 删除任务组 */
export function deleteTaskGroup(id: number) {
  return http.del(`${BASE_URL}/group/${id}`)
}

/** @desc 查询任务列表（标准导出） */
export const listTask = (params: any) => {
  return http.get('/project-task/list', params)
}

/** @desc 获取任务详情 */
export function getTask(id: number) {
  return http.get<T.TaskResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增任务 */
export function addTask(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改任务 */
export function updateTask(data: any, id: number) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 更新任务状态 */
export function updateTaskStatus(data: any, id: number) {
  return http.patch(`${BASE_URL}/${id}/status`, data)
}

/** @desc 更新任务进度 */
export function updateTaskProgress(data: any, id: number) {
  return http.patch(`${BASE_URL}/${id}/progress`, data)
}

/** @desc 删除任务 */
export function deleteTask(id: number) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导入任务 */
export function importTask(file: File, projectId: number) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('projectId', projectId.toString())
  return http.post(`${BASE_URL}/import`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
} 