import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TaskVO, TaskForm, TaskQuery } from '@/api/task/types';

/**
 * 查询全部任务列表
 * @param query
 * @returns {*}
 */

export const listTask = (query?: TaskQuery): AxiosPromise<{ records: TaskVO[] }> => {
  return request({
    url: '/sys/task/listPage',
    method: 'post',
    data: query
  });
};

/**
 * 查询全部任务详细
 * @param id
 */
export const getTask = (id: string | number): AxiosPromise<TaskVO> => {
  return request({
    url: '/sys/task/getTaskDetail',
    method: 'post',
    data: { id }
  });
};

/**
 * 新增全部任务
 * @param data
 */
export const addTask = (data: TaskForm) => {
  return request({
    url: '/sys/task/save',
    method: 'post',
    data: data
  });
};

/**
 * 修改全部任务
 * @param data
 */
export const updateTask = (data: TaskForm) => {
  return request({
    url: '/task/task',
    method: 'put',
    data: data
  });
};

/**
 * 删除全部任务
 * @param id
 */
export const delTask = (id: string | number | Array<string | number>) => {
  return request({
    url: '/sys/task/delete',
    method: 'post',
    data: { id }
  });
};

/**
 * 未能完成&取消任务
 * @param id
 */
export const updateStatus = (type: string, data: { taskId?: string | number, remark: string }) => {
  return request({
    url: '/sys/task/' + type,
    method: 'post',
    data: data
  });
};
