import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DmsRepairInstanceVO, DmsRepairInstanceForm, DmsRepairInstanceQuery } from '@/api/dms/dmsRepairInstance/types';

/**
 * 查询检修工单列表
 * @param query
 * @returns {*}
 */

export const listDmsRepairInstance = (query?: DmsRepairInstanceQuery): AxiosPromise<DmsRepairInstanceVO[]> => {
  return request({
    url: '/dms/dmsRepairInstance/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询检修工单详细
 * @param repairInstanceId
 */
export const getDmsRepairInstance = (repairInstanceId: string | number): AxiosPromise<DmsRepairInstanceVO> => {
  return request({
    url: '/dms/dmsRepairInstance/' + repairInstanceId,
    method: 'get'
  });
};

/**
 * 新增检修工单
 * @param data
 */
export const addDmsRepairInstance = (data: DmsRepairInstanceForm) => {
  return request({
    url: '/dms/dmsRepairInstance',
    method: 'post',
    data: data
  });
};

/**
 * 修改检修工单
 * @param data
 */
export const updateDmsRepairInstance = (data: DmsRepairInstanceForm) => {
  return request({
    url: '/dms/dmsRepairInstance',
    method: 'put',
    data: data
  });
};

/**
 * 删除检修工单
 * @param repairInstanceId
 */
export const delDmsRepairInstance = (repairInstanceId: string | number | Array<string | number>) => {
  return request({
    url: '/dms/dmsRepairInstance/' + repairInstanceId,
    method: 'delete'
  });
};


/**
 * 下拉框查询检修工单列表
 * @param query
 * @returns {*}
 */
export function getDmsRepairInstanceList (query) {
    return request({
        url: '/dms/dmsRepairInstance/getDmsRepairInstanceList',
        method: 'get',
        params: query
    });
};

/**
 * 更新检修工单的工作流定义ID
 * @param repairInstanceId 检修工单的ID
 * @param wfDefinitionId 工作流定义的ID
 * @return 如果更新成功返回true，否则返回false
 */
export function updateWfDefinitionIdById (repairInstanceId: string | number, wfDefinitionId: string | number) {
  return request({
    url: '/dms/dmsRepairInstance/updateWfDefinitionIdById',
    method: 'post',
    params: {
      repairInstanceId,
      wfDefinitionId
    }
  });
};

