import type { TaskItem, TaskParams } from '@/pages/Demo/TaskBoard/data';
import { request } from '@umijs/max';

/** 获取任务列表 GET /api/demo/tasks */
export async function queryTaskList(
  params: TaskParams,
  options?: { [key: string]: any },
) {
  return request<{
    data: TaskItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/demo/tasks', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建任务 POST /api/demo/tasks */
export async function addTask(
  data: Partial<TaskItem>,
  options?: { [key: string]: any },
) {
  return request<TaskItem>('/api/demo/tasks', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/** 更新任务 PUT /api/demo/tasks */
export async function updateTask(
  data: Partial<TaskItem>,
  options?: { [key: string]: any },
) {
  return request<TaskItem>('/api/demo/tasks', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}

/** 删除任务 DELETE /api/demo/tasks */
export async function removeTask(
  data: { id: string },
  options?: { [key: string]: any },
) {
  return request<Record<string, any>>('/api/demo/tasks', {
    method: 'DELETE',
    data,
    ...(options || {}),
  });
}
