import request from '@/config/axios'

export interface TaskManagementVO {
  id?: number
  name?: string
  taskType?: number
  deviceList?: string
  projectForm?: string | number
  startDate?: string
  endDate?: string
  cronExpression?: string
  operableUsers?: string
  enabled?: boolean
  execFrequency?: string
  frequencyValue?: string
  time?: string
  validMinutes?: number
  creator?: string
  createTime?: string
  updateTime?: string
}

export const TaskManagementApi = {
  getTaskManagementPage: async (params: any) => {
    return await request.get({ url: `/mes/task-management/page`, params })
  },

  createTaskManagementTicket: async (id: number | string) => {
    return await request.post({ url: `/mes/task-management/createTicket`, params: { id } })
  },

  createTaskManagement: async (data: TaskManagementVO) => {
    return await request.post({ url: `/mes/task-management/create`, data })
  },

  updateTaskManagement: async (data: TaskManagementVO) => {
    return await request.put({ url: `/mes/task-management/update`, data })
  },

  deleteTaskManagement: async (ids: string) => {
    return await request.delete({ url: `/mes/task-management/delete?ids=` + ids })
  },

  exportTaskManagement: async (params: any) => {
    return await request.download({ url: `/mes/task-management/export-excel`, params })
  },

  updateTaskManagementEnabled: async (id: number | string, enabled: string) => {
    const data = { id, enabled }
    return await request.put({ url: `/mes/task-management/update-enabled`, data })
  }
}
