import request from '@/config/axios'

export interface TicketManagementVO {
  id?: number
  subjectId?: string
  planId?: string
  planNo?: string
  deviceName?: string
  planType?: string | number
  configName?: string
  jobStatus?: string | number
  jobResult?: string
  jobUser?: string
  taskTime?: string
  taskEndTime?: string
  cancelReason?: string
  remark?: string
  creator?: string
  createTime?: string
}

export interface TicketResultVO {
  id?: number
  inspectionItemName?: string
  inspectionMethod?: string
  judgmentCriteria?: string
  valueType?: string | number
  textInput?: string
  inspectionResult?: string | number
  images?: string
  remark?: string
  inspectionTime?: string
  inspector?: string
  managementId?: string | number
  createTime?: string
}

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

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

  batchUpdateTicketStatus: async (data: { ids: string; jobStatus: string | number; cancelReason?: string }) => {
    return await request.put({ url: `/mes/ticket-management/batchUpdateStatus`, data })
  },

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

  batchUpdateTicketResults: async (data: TicketResultVO[]) => {
    return await request.put({ url: `/mes/ticket-results/batchUpdate`, data })
  },

  getInspectionByDeviceId: async (params: { deviceId: number; startTime?: string; endTime?: string }) => {
    return await request.get({ url: `/mes/ticket-management/getInspectionByDeviceId`, params })
  },

  exportInspection: async (params: { deviceId: number; startTime?: string; endTime?: string }) => {
    return await request.download({ url: `/mes/ticket-management/export-excel-inspection`, params })
  },

  getMaintenanceByDeviceId: async (params: { deviceId: number; startTime?: string; endTime?: string }) => {
    return await request.get({ url: `/mes/ticket-management/getMaintenanceByDeviceId`, params })
  },

  exportMaintenance: async (params: { deviceId: number; startTime?: string; endTime?: string }) => {
    return await request.download({ url: `/mes/ticket-management/export-excel-maintenance`, params })
  }
}
