import { addOtaPkg, delOtaPkg, getOtaPkgById, getOtaPkgList, getOtaPkgPage } from '@/api/iot/ota'
import { PkgTypeEnum } from '@/enum/common'
import { message } from 'ant-design-vue'

export class OtaController {
  static pkgTypeMap = new Map([
    [PkgTypeEnum.FILE_URL, { value: PkgTypeEnum.FILE_URL, label: '地址访问' }],
    [PkgTypeEnum.FILE_ZIP, { value: PkgTypeEnum.FILE_ZIP, label: 'zip包' }]
  ])

  static pkgTypeList = [{ value: PkgTypeEnum.FILE_URL, label: '地址访问' }, { value: PkgTypeEnum.FILE_ZIP, label: 'zip包' }]

  static async page (params: IOT.API.OTA.QueryParams = {
    page: 1,
    pageSize: 10,
    label: '',
    version: '',
    pkgType: ''
  }) {
    return await getOtaPkgPage(params)
  }

  static async list (params = {
    label: '',
    version: '',
    pkgType: '',
    limit: 10000
  }) {
    return await getOtaPkgList(params as any)
  }

  static async add (data: IOT.API.OTA.BodyParams) {
    await addOtaPkg(data)
    message.success('新增成功')
  }

  static async update (data: IOT.API.OTA.BodyParams) {
    // await updateOtaPkg(data)
    message.success('修改成功')
  }

  static async del (id: string) {
    await delOtaPkg(id)
    message.success('删除成功')
  }

  static async byId (id: string) {
    return await getOtaPkgById(id)
  }
}
