import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DmsBillsMaintInstanceVO, DmsBillsMaintInstanceForm, DmsBillsMaintInstanceQuery } from '@/api/dms/dmsBillsMaintInstance/types';

/**
 * 查询保养工单列表
 * @param query
 * @returns {*}
 */

export const listDmsBillsMaintInstance = (query?: DmsBillsMaintInstanceQuery): AxiosPromise<DmsBillsMaintInstanceVO[]> => {
  return request({
    url: '/dms/dmsBillsMaintInstance/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询保养工单详细
 * @param maintInstanceId
 */
export const getDmsBillsMaintInstance = (maintInstanceId: string | number): AxiosPromise<DmsBillsMaintInstanceVO> => {
  return request({
    url: '/dms/dmsBillsMaintInstance/' + maintInstanceId,
    method: 'get'
  });
};

/**
 * 新增保养工单
 * @param data
 */
export const addDmsBillsMaintInstance = (data: DmsBillsMaintInstanceForm) => {
  return request({
    url: '/dms/dmsBillsMaintInstance',
    method: 'post',
    data: data
  });
};

/**
 * 修改保养工单
 * @param data
 */
export const updateDmsBillsMaintInstance = (data: DmsBillsMaintInstanceForm) => {
  return request({
    url: '/dms/dmsBillsMaintInstance',
    method: 'put',
    data: data
  });
};

/**
 * @description: 获取设备维保统计
 * @param {R} params
 * @return {R}
 */
export const getDmsDeviceMaintenanceStats = (params: any) => {
  return request({
    url: '/dms/dmsBillsMaintInstance/getDmsDeviceMaintenanceStats',
    method: 'get',
    params
  });
};

/**
 * 删除保养工单
 * @param maintInstanceId
 */
export const delDmsBillsMaintInstance = (maintInstanceId: string | number | Array<string | number>) => {
  return request({
    url: '/dms/dmsBillsMaintInstance/' + maintInstanceId,
    method: 'delete'
  });
};

/**
 * Get maintenance instance count
 * @returns
 */
export const getMaintInstanceCount = (params: any): AxiosPromise<number> => {
  return request({
    url: '/dms/dmsBillsMaintInstance/count',
    method: 'get',
    params
  });
};


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

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

