import { request } from '@/utils/request'

// MES设备维修保养记录表 类型定义
export interface MaintenanceRecord {
  recordId?:  string

  equipmentId?:  string

  recordType?:  string

  itemContent?:  string

  handleContent?:  string

  executorId?: number

  startTime?:  string

  endTime?:  string

  recordStatus?:  string

  createTime?:  string

  updateTime?:  string

}

// MES设备维修保养记录表 API
export const maintenanceRecordApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; recordId?:  string }) {
    return request({ url: '/biz/maintenanceRecord/page', method: 'get', params })
  },

  // 获取详情
  detail(recordId:  string) {
    return request({ url: `/biz/maintenanceRecord/${recordId}`, method: 'get' })
  },

  // 新增
  create(data: MaintenanceRecord) {
    return request({ url: '/biz/maintenanceRecord', method: 'post', data })
  },

  // 修改
  update(data: MaintenanceRecord) {
    return request({ url: '/biz/maintenanceRecord', method: 'put', data })
  },

  // 删除
  delete(recordIds:  string[]) {
    return request({ url: `/biz/maintenanceRecord/${recordIds.join(',')}`, method: 'delete' })
  },

  // 导出
  export(params?: { ids?:  string[]; recordId?:  string }) {
    const p: Record<string, any> = {}
    if (params?.ids?.length) p.ids = params.ids.join(',')
    if (params?.recordId !== undefined && params?.recordId !== null) p.recordId = params.recordId
    return request({ url: `/biz/maintenanceRecord/export`, method: 'get', params: p, responseType: 'blob' })
  },

  // 导入
  importData(file: File) {
    const formData = new FormData()
    formData.append('file', file)
    return request<{ success: number; fail: number; errors: string[] }>({
      url: `/biz/maintenanceRecord/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

  // 下载导入模板
  downloadTemplate() {
    return request({ url: `/biz/maintenanceRecord/template`, method: 'get', responseType: 'blob' })
  }
}
