import request from '@/config/axios'

export interface DeviceAttrTemplateVO {
  id?: number
  name: string
  deviceCategoryId: number
  code: string
  attrs: DeviceTemplateAttrs
  description: string
  status: number
  sort: number
  remark: string
}

/**
 * 设备专有属性 类型
 */
export interface DeviceTemplateAttrs {
  [key: string]: any
}

// 根据设备分类id查询设备专有属性模板
export const getAttrTemplateByDeviceCategoryId = async (params: any): Promise<any> => {
  return await request.get({ url: '/pms/iot-device-category-template/list-by-device-category-id?deviceCategoryId='+ params })
}

// 查询 设备属性模板 列表
export const getDeviceTemplatePage = async (params: PageParam) => {
  return await request.get({ url: '/pms/iot-device-category-template/page', params })
}

// 查询 设备属性模板 详情
export const getDeviceTemplate = async (id: number) => {
  return await request.get({ url: '/pms/iot-device-category-template/get?id=' + id })
}

// 新增 设备属性模板
export const createDeviceTemplate = async (data: DeviceAttrTemplateVO) => {
  return await request.post({ url: '/pms/iot-device-category-template/create', data: data })
}

// 修改 设备属性模板
export const updateDeviceTemplate = async (params: DeviceAttrTemplateVO) => {
  return await request.put({ url: '/pms/iot-device-category-template/update', data: params })
}

// 设备属性模板状态修改
export const updateDeviceTemplateStatus = (id: number, status: number) => {
  const data = {
    id,
    status
  }
  return request.put({ url: '/pms/iot-device-category-template/update-status', data: data })
}

// 删除 设备属性模板
export const deleteDeviceTemplate = async (id: number) => {
  return await request.delete({ url: '/pms/iot-device-category-template/delete?id=' + id })
}
