import request from '@/config/axios'

export interface ZjTaskVO {
  id: number
  code: string
  name: string
  type: string
  schemaId: number
  schemaName: string
  remark: string
  ticket: string
  orgType: string
  managerId: string
  managerName: string
  executorId: string
  executorName: string
  status: string
  cancelReason?: string
  result: string
  createTime: string
  roleIds?: number[]
}

export interface ZjTaskResultVO {
  id: number
  name: string
  tool: string
  standardVal: number
  unit: string
  upperVal: number
  lowerVal: number
  remark: string
  images?: string
  zjResult?: number
}

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

  createZjTask: async (data: ZjTaskVO) => {
    return await request.post({ url: `/mes/zj-task/create`, data })
  },

  updateZjTask: async (data: ZjTaskVO) => {
    return await request.put({ url: `/mes/zj-task/update`, data })
  },

  deleteZjTask: async (id: number) => {
    return await request.delete({ url: `/mes/zj-task/delete?id=` + id })
  },

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

  batchUpdateZjTaskStatus: async (data: { ids: string; status: string | number; cancelReason?: string }) => {
    return await request.put({ url: `/mes/zj-task/batchUpdateStatus`, data })
  },

  getZjTaskResultPage: async (params: any) => {
    return await request.get({ url: `/mes/zj-task-results/page`, params })
  },

  batchUpdateZjTaskResults: async (
    results: { id: number; taskId: number; images?: string; zjResult: number }[],
  ) => {
    return await request.post({ url: `/mes/zj-task-results/batch-update`, data: { results } })
  },
}
