import request from '@/config/axios'

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

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

// 根据设备分类id查询设备专有属性模板
export const getAttrTemplateByModelCategoryId = async (params: any): Promise<any> => {
  return await request.get({ url: '/rq/iot-model-template/list-by-model-category-id?deviceCategoryId='+ params })
}
// 查询是否关联
export const getIsRelated= async (deviceId: number | undefined) => {
  return await request.get({ url: `/rq/iot-model-template/isRelated?deviceId=`+deviceId })
}

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

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

// 新增 设备属性模板
export const createModelTemplate = async (data: ModelAttrTemplateVO) => {
  return await request.post({ url: '/rq/iot-model-template/create', data: data })
}

// 修改 设备属性模板
export const updateModelTemplate = async (params: ModelAttrTemplateVO) => {
  return await request.put({ url: '/rq/iot-model-template/update', data: params })
}

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

// 删除 设备属性模板
export const deleteModelTemplate = async (id: number | undefined) => {
  return await request.delete({ url: '/rq/iot-model-template/delete?id=' + id })
}
