import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DmsBillsMaintDetailVO, DmsBillsMaintDetailForm, DmsBillsMaintDetailQuery } from '@/api/dms/dmsBillsMaintDetail/types';

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

export const listDmsBillsMaintDetail = (query?: DmsBillsMaintDetailQuery): AxiosPromise<DmsBillsMaintDetailVO[]> => {
  return request({
    url: '/dms/dmsBillsMaintDetail/list',
    method: 'get',
    params: query
  });
};

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

/**
 * 新增保养工单明细
 * @param data
 */
export const addDmsBillsMaintDetail = (data: DmsBillsMaintDetailForm) => {
  return request({
    url: '/dms/dmsBillsMaintDetail',
    method: 'post',
    data: data
  });
};

/**
 * 修改保养工单明细
 * @param data
 */
export const updateDmsBillsMaintDetail = (data: DmsBillsMaintDetailForm) => {
  return request({
    url: '/dms/dmsBillsMaintDetail',
    method: 'put',
    data: data
  });
};

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


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

/**
 * 根据设备ID查询维保工单列表
 * @param machineId 设备ID
 */
export const getMaintInstancesByMachineId = (machineId: string | number) => {
  return request({
    url: `/dms/dmsBillsMaintDetail/getMaintInstancesByMachineId/${machineId}`,
    method: 'get'
  });
};

/**
 * 根据设备ID统计维保工单数量
 * @param machineId 设备ID
 */
export const countMaintInstancesByMachineId = (machineId: string | number) => {
  return request({
    url: `/dms/dmsBillsMaintDetail/countMaintInstancesByMachineId/${machineId}`,
    method: 'get'
  });
};
