import request from '@/config/axios'

// 网关 VO
export interface GatewayVO {
  id: number // ID
  adminIp: string // 管理地址
  username: string // 管理账号
  password: string // 管理密码
  gatewayName: string // 网关名字
  remark: string // 备注
  isEnable: boolean // 是否启用
  gatewayCode: string // 网关编码
  gatewayStatus: string // 网关状态
  topic: string // 订阅主题
}

// 网关 API
export const GatewayApi = {
  // 查询网关分页
  getGatewayPage: async (params: any) => {
    return await request.get({ url: `/iot/gateway/page`, params })
  },

  // 查询网关详情
  getGateway: async (id: number) => {
    return await request.get({ url: `/iot/gateway/get?id=` + id })
  },

  // 新增网关
  createGateway: async (data: GatewayVO) => {
    return await request.post({ url: `/iot/gateway/create`, data })
  },

  // 修改网关
  updateGateway: async (data: GatewayVO) => {
    return await request.put({ url: `/iot/gateway/update`, data })
  },

  // 删除网关
  deleteGateway: async (id: number) => {
    return await request.delete({ url: `/iot/gateway/delete?id=` + id })
  },

  // 导出网关 Excel
  exportGateway: async (params) => {
    return await request.download({ url: `/iot/gateway/export-excel`, params })
  },

// ==================== 子表（物联设备） ====================

  // 获得物联设备分页
  getDevicePage: async (params) => {
    return await request.get({ url: `/iot/gateway/device/page`, params })
  },
  // 新增物联设备
  createDevice: async (data) => {
    return await request.post({ url: `/iot/gateway/device/create`, data })
  },

  // 修改物联设备
  updateDevice: async (data) => {
    return await request.put({ url: `/iot/gateway/device/update`, data })
  },

  // 删除物联设备
  deleteDevice: async (id: number) => {
    return await request.delete({ url: `/iot/gateway/device/delete?id=` + id })
  },

  // 获得物联设备
  getDevice: async (id: number) => {
    return await request.get({ url: `/iot/gateway/device/get?id=` + id })
  },
}
