import request from '@/config/axios'

export interface BomVO {
  id?: number
  name: string
  code: string
  parentId: number
  deviceCategoryId: number
  status: number
  sort: number
  type?: number[] // bom节点属性 维修 or 保养
  createTime: Date
}

export interface BomListTreeReqVO extends PageParam {
  deviceCategoryId?: number
  name?: string
  status?: number
}

// 查询bom（精简)列表
export const getSimpleBomList = async (params: PageParam): Promise<BomVO[]> => {
  return await request.get({ url: '/rq/iot-bom/simple-list', params })
}

// 查询Bom树列表
export const getBomPage = async (params: PageParam) => {
  return await request.get({ url: '/rq/iot-bom/list', params })
}

// 查询Bom树形列表
export const getBomListTree = async (params: BomListTreeReqVO) => {
  return await request.get({ url: '/rq/iot-bom/listTree', params })
}

// 查询Bom树节点详情
export const getBom = async (id: number) => {
  return await request.get({ url: '/rq/iot-bom/get?id=' + id })
}

// 新增Bom树节点
export const createBomNode = async (data: BomVO) => {
  return await request.post({ url: '/rq/iot-bom/create', data: data })
}

// 修改Bom树节点
export const updateBomNode = async (params: BomVO) => {
  return await request.put({ url: '/rq/iot-bom/update', data: params })
}

// 删除Bom树节点
export const deleteBomNode = async (id: number) => {
  return await request.delete({ url: '/rq/iot-bom/delete?id=' + id })
}
