import { delTask, getTaskById, getTaskCount, getTaskPage, postTask, trackTasById, trackTaskPage, updateTask, updateTaskStatus } from '@/api/iot/task'
import { message } from 'ant-design-vue'

export class TaskController {
  static taskTypeMap = new Map([
    ['DEVICE_CMD', { key: 'DEVICE_CMD', label: '设备命令' }],
    ['DEVICE_MSG', { key: 'DEVICE_MSG', label: '设备消息' }],
    ['DEVICE_DISCONNECT', { key: 'DEVICE_DISCONNECT', label: '设备断开连接' }]
  ])

  static taskTypeList = ['DEVICE_CMD', 'DEVICE_MSG', 'DEVICE_DISCONNECT']

  static taskStatisticsMap = new Map([
    ['TOTAL', { label: '总数', color: 'green' }],
    ['DISABLE', { label: '禁用数', color: 'grey' }],
    ['ENABLE', { label: '启用数量', color: 'orange' }]
  ])

  static async page (params: {page: number, pageSize: number, taskLabel?: string, status?: boolean | string}) {
    return getTaskPage(params)
  }

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

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

  static async statistics () {
    return getTaskCount()
  }

  static async add (data: any) {
    await postTask(data)
    message.success('新增成功')
  }

  static async update (data: any) {
    await updateTask(data)
    message.success('修改成功')
  }

  static async updateStatus (id: string, status: boolean) {
    await updateTaskStatus(id, status)
    message.success('修改成功')
  }

  static async trackTaskPage (params: COMMON.API.QueryParams | { taskId: string }) {
    return await trackTaskPage(params)
  }

  static async trackTasById (id: string) {
    return await trackTasById(id)
  }
}
