import request from '@/service/request'

export const getTaskPage = (params: {page: number, pageSize: number, taskLabel?: string, status?: boolean | string}) => {
  return request<IOT.API.TASK.Task[]>({
    url: '/task/page',
    method: 'GET',
    params
  })
}

export const postTask = (data: any) => {
  return request<string>({
    url: '/task',
    method: 'POST',
    data
  })
}

export const updateTask = (data: any) => {
  return request<string>({
    url: '/task',
    method: 'PUT',
    data
  })
}

export const getTaskCount = () => {
  return request<IOT.API.TASK.Statistics>({
    url: '/task/count',
    method: 'GET'
  })
}

export const getTaskById = (id: string) => {
  return request<IOT.API.TASK.Task>({
    url: `/task/${id}`,
    method: 'GET'
  })
}

export const updateTaskStatus = (id: string, status: boolean) => {
  return request<IOT.API.TASK.Task>({
    url: `/task/status?id=${id}&status=${status}`,
    method: 'PUT'
  })
}

export const delTask = (id: string) => {
  return request<string>({
    url: `/task/${id}`,
    method: 'DELETE'
  })
}

export const trackTaskPage = (params: COMMON.API.QueryParams | { taskId: string }) => {
  return request<IOT.API.TASK.TrackTask>({
    url: '/taskTrace/page',
    method: 'GET',
    params
  })
}

export const trackTasById = (id: string) => {
  return request<IOT.API.TASK.TrackTask>({
    url: `/taskTrace/${id}`,
    method: 'GET'
  })
}
