import request from '@/config/axios'

// PMS 设备BOM物料关联 VO
export interface IotDeviceMaterialVO {
  id: number // 主键
  deviceCategoryId: number // 所属设备分类
  deviceId: number // 所属设备
  name: string // 设备BOM节点名称
  bomNodeId: number // 设备BOM节点id
  code: string // 设备BOM节点编码
  materialId: number // 物料id
  quantity: number // 数量
  status: number // 状态 0启用  1停用
  remark: string // 备注
}

// PMS 设备BOM物料关联 API
export const IotDeviceMaterialApi = {
  // 查询PMS 设备BOM物料关联分页
  getIotDeviceMaterialPage: async (params: any) => {
    return await request.get({ url: `/pms/iot-device-material/page`, params })
  },

  // 查询PMS 设备BOM物料关联详情
  getIotDeviceMaterial: async (id: number) => {
    return await request.get({ url: `/pms/iot-device-material/get?id=` + id })
  },

  // 新增PMS 设备BOM物料关联
  createIotDeviceMaterial: async (data: IotDeviceMaterialVO) => {
    return await request.post({ url: `/pms/iot-device-material/create`, data })
  },

  // 设备BOM节点可能关联多个物料
  addMaterials: async (data: any) => {
    return await request.post({ url: '/pms/iot-device-material/addMaterials', data })
  },

  // 修改PMS 设备BOM物料关联
  updateIotDeviceMaterial: async (data: IotDeviceMaterialVO) => {
    return await request.put({ url: `/pms/iot-device-material/update`, data })
  },

  // 删除PMS 设备BOM物料关联
  deleteIotDeviceMaterial: async (id: number) => {
    return await request.delete({ url: `/pms/iot-device-material/delete?id=` + id })
  },

  // 导出PMS 设备BOM物料关联 Excel
  exportIotDeviceMaterial: async (params) => {
    return await request.download({ url: `/pms/iot-device-material/export-excel`, params })
  },

  deleteDeviceMaterial: async (bomNodeId: number, code: string) => {
    return await request.delete({ url: '/pms/iot-device-material/deleteDeviceMaterial?bomNodeId=' + bomNodeId + '&code=' + code })
  }
}
