import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DmsBillsFaultInstanceVO, DmsBillsFaultInstanceForm, DmsBillsFaultInstanceQuery } from '@/api/dms/dmsBillsFaultInstance/types';

/**
 * 查询故障报修工单;手工创建故障报修工单列表
 * @param query
 * @returns {*}
 */

export const listDmsBillsFaultInstance = (query?: DmsBillsFaultInstanceQuery): AxiosPromise<DmsBillsFaultInstanceVO[]> => {
  return request({
    url: '/dms/dmsBillsFaultInstance/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询故障报修工单;手工创建故障报修工单详细
 * @param repairInstanceId
 */
export const getDmsBillsFaultInstance = (repairInstanceId: string | number): AxiosPromise<DmsBillsFaultInstanceVO> => {
  return request({
    url: '/dms/dmsBillsFaultInstance/' + repairInstanceId,
    method: 'get'
  });
};

/**
 * 新增故障报修工单;手工创建故障报修工单
 * @param data
 */
export const addDmsBillsFaultInstance = (data: DmsBillsFaultInstanceForm) => {
  return request({
    url: '/dms/dmsBillsFaultInstance',
    method: 'post',
    data: data
  });
};

/**
 * 修改故障报修工单;手工创建故障报修工单
 * @param data
 */
export const updateDmsBillsFaultInstance = (data: DmsBillsFaultInstanceForm) => {
  return request({
    url: '/dms/dmsBillsFaultInstance',
    method: 'put',
    data: data
  });
};

/**
 * 删除故障报修工单;手工创建故障报修工单
 * @param repairInstanceId
 */
export const delDmsBillsFaultInstance = (repairInstanceId: string | number | Array<string | number>) => {
  return request({
    url: '/dms/dmsBillsFaultInstance/' + repairInstanceId,
    method: 'delete'
  });
};

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


/**
 * 下拉框查询故障报修工单;手工创建故障报修工单列表
 * @param query
 * @returns {*}
 */
export function getDmsBillsFaultInstanceList (query) {
    return request({
        url: '/dms/dmsBillsFaultInstance/getDmsBillsFaultInstanceList',
        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/dmsBillsFaultInstance/updateWfDefinitionIdById',
    method: 'post',
    params: {
      repairInstanceId,
      wfDefinitionId
    }
  });
}

/**
 * 审批故障报修工单
 * @param repairInstanceId 工单ID
 * @param approveStatus 审批状态（2-审批成功，3-审批失败）
 * @param message 审批意见
 */
export function approveWorkOrder(repairInstanceId: string | number, approveStatus: string, message?: string) {
  return request({
    url: '/dms/dmsBillsFaultInstance/approve',
    method: 'post',
    params: {
      repairInstanceId,
      approveStatus,
      message
    }
  });
}

/**
 * 主管确认维修结果
 * @param repairInstanceId 工单ID
 * @param confirmResult 确认结果（1-确认完成）
 * @param confirmUser 确认人
 */
export function confirmRepairResult(repairInstanceId: string | number, confirmResult: string, confirmUser?: string) {
  return request({
    url: '/dms/dmsBillsFaultInstance/confirm',
    method: 'post',
    params: {
      repairInstanceId,
      confirmResult,
      confirmUser
    }
  });
}
