import { get, post, put, del } from './request'

export interface TaskParams {
  projectId?: number
  taskType: string
  urgentLevel: string
  remark?: string
  staffId?: number
  vehicleId?: number
}

export function getTaskList(pageNum = 1, pageSize = 10) {
  return get('/task/list', { pageNum, pageSize })
}

export function getTaskDetail(taskId: number) {
  return get(`/task/${taskId}`)
}

export function createTask(data: TaskParams) {
  return post('/task', data)
}

export function updateTask(taskId: number, data: Partial<TaskParams>) {
  return put('/task', { taskId, ...data })
}

export function deleteTask(taskId: number) {
  return del(`/task/${taskId}`)
}

export function advanceTaskStep(taskId: number, step: number, data?: Record<string, any>) {
  return post(`/task/${taskId}/step/${step}`, data)
}

export function urgeTask(taskId: number, urgeReason: string, operatorId: number, operatorName: string) {
  return post(`/task/${taskId}/urge`, { taskId, urgeReason, operatorId, operatorName })
}

export function cancelTask(taskId: number, cancelReason: string, operatorId: number, operatorName: string) {
  return post(`/task/${taskId}/cancel`, { taskId, cancelReason, operatorId, operatorName })
}

export function getTaskLogs(taskId: number) {
  return get(`/task/${taskId}/logs`)
}
