import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TaskInstanceVO, TaskInstanceForm, TaskInstanceId, TaskInstanceIds, TaskInstanceQuery } from '@/api/wcs/taskInstance/types';

/**
 * 查询主任务执行列表
 * @param query
 * @returns {*}
 */

export const listTaskInstance = (query?: TaskInstanceQuery): AxiosPromise<TaskInstanceVO[]> => {
  return request({
    url: '/wcs/taskInstance/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询主任务执行详细
 * @param id
 */
export const getTaskInstance = (id: TaskInstanceId): AxiosPromise<TaskInstanceVO> => {
  return request({
    url: '/wcs/taskInstance/' + id,
    method: 'get'
  });
};

/**
 * 批量查询主任务执行详细
 * @param ids
 */
export const getTaskInstanceByIds = (ids: TaskInstanceIds): AxiosPromise<TaskInstanceVO[]> => {
  return request({
    url: '/wcs/taskInstance/listByIds',
    method: 'post',
    data: ids
  });
};

/**
 * 统计主任务执行数量
 * @param query
 */
export const countTaskInstance = (query?: TaskInstanceQuery): AxiosPromise<number> => {
  return request({
    url: '/wcs/taskInstance/count',
    method: 'get',
    params: query
  });
};

/**
 * 判断是否存在符合条件的主任务执行
 * @param query
 */
export const existsTaskInstance = (query?: TaskInstanceQuery): AxiosPromise<boolean> => {
  return request({
    url: '/wcs/taskInstance/exists',
    method: 'get',
    params: query
  });
};

/**
 * 新增主任务执行
 * @param data
 */
export const addTaskInstance = (data: TaskInstanceForm) => {
  return request({
    url: '/wcs/taskInstance',
    method: 'post',
    data: data
  });
};

/**
 * 修改主任务执行
 * @param data
 */
export const updateTaskInstance = (data: TaskInstanceForm) => {
  return request({
    url: '/wcs/taskInstance',
    method: 'put',
    data: data
  });
};

/**
 * 删除主任务执行
 * @param id
 */
export const delTaskInstance = (id: TaskInstanceId | TaskInstanceIds) => {
  return request({
    url: '/wcs/taskInstance/' + id,
    method: 'delete'
  });
};
