import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DmsInspectInstanceDetailVO, DmsInspectInstanceDetailForm, DmsInspectInstanceDetailQuery } from '@/api/dms/dmsInspectInstanceDetail/types';

/**
 * 查询点巡检工单明细列表
 * @param query
 * @returns {*}
 */

export const listDmsInspectInstanceDetail = (query?: DmsInspectInstanceDetailQuery): AxiosPromise<DmsInspectInstanceDetailVO[]> => {
  return request({
    url: '/dms/dmsInspectInstanceDetail/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询点巡检工单明细详细
 * @param instanceDetailId
 */
export const getDmsInspectInstanceDetail = (instanceDetailId: string | number): AxiosPromise<DmsInspectInstanceDetailVO> => {
  return request({
    url: '/dms/dmsInspectInstanceDetail/' + instanceDetailId,
    method: 'get'
  });
};

/**
 * 新增点巡检工单明细
 * @param data
 */
export const addDmsInspectInstanceDetail = (data: DmsInspectInstanceDetailForm) => {
  return request({
    url: '/dms/dmsInspectInstanceDetail',
    method: 'post',
    data: data
  });
};

/**
 * 修改点巡检工单明细
 * @param data
 */
export const updateDmsInspectInstanceDetail = (data: DmsInspectInstanceDetailForm) => {
  return request({
    url: '/dms/dmsInspectInstanceDetail',
    method: 'put',
    data: data
  });
};

/**
 * 删除点巡检工单明细
 * @param instanceDetailId
 */
export const delDmsInspectInstanceDetail = (instanceDetailId: string | number | Array<string | number>) => {
  return request({
    url: '/dms/dmsInspectInstanceDetail/' + instanceDetailId,
    method: 'delete'
  });
};


/**
 * 下拉框查询点巡检工单明细列表
 * @param query
 * @returns {*}
 */
export function getDmsInspectInstanceDetailList (query) {
    return request({
        url: '/dms/dmsInspectInstanceDetail/getDmsInspectInstanceDetailList',
        method: 'get',
        params: query
    });
};

/**
 * 根据设备ID查询巡检工单列表（关联主表信息）
 * @param machineId 设备ID
 */
export const getInspectInstancesByMachineId = (machineId: string | number) => {
  return request({
    url: `/dms/dmsInspectInstanceDetail/getInspectInstancesByMachineId/${machineId}`,
    method: 'get'
  });
};

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