import request from '@/config/axios'

// 设备维修记录 VO
export interface DvRepairVO {
  id: number // ID
  repairCode: string // 维修单编号
  repairName: string // 维修单名称
  machineryId: number // 设备ID
  machineryCode: string // 设备编码
  machineryName: string // 设备名称
  machineryBrand: string // 品牌
  machinerySpec: string // 规格型号
  machineryTypeId: number // 设备类型
  requireDate: Date // 报修日期
  finishDate: Date // 完成日期
  confirmDate: Date // 验收日期
  repairResult: string // 维修结果
  acceptedBy: string // 维修人员
  confirmBy: string // 验收人员
  status: string // 单据状态
  remark: string // 备注
}

// 设备维修记录 API
export const DvRepairApi = {
  // 查询设备维修记录分页
  getDvRepairPage: async (params: any) => {
    return await request.get({ url: `/mes/dv-repair/page`, params })
  },

  // 查询设备维修记录详情
  getDvRepair: async (id: number) => {
    return await request.get({ url: `/mes/dv-repair/get?id=` + id })
  },

  // 新增设备维修记录
  createDvRepair: async (data: DvRepairVO) => {
    return await request.post({ url: `/mes/dv-repair/create`, data })
  },

  // 修改设备维修记录
  updateDvRepair: async (data: DvRepairVO) => {
    return await request.put({ url: `/mes/dv-repair/update`, data })
  },

  // 删除设备维修记录
  deleteDvRepair: async (ids: string) => {
    return await request.delete({ url: `/mes/dv-repair/delete?ids=` + ids })
  },

  // 导出设备维修记录 Excel
  exportDvRepair: async (params) => {
    return await request.download({ url: `/mes/dv-repair/export-excel`, params })
  },

  updateDvRepairStatus: async (data: any) => {
    return await request.put({ url: `/mes/dv-repair/updateDvRepairStatus`, data })
  },

// ==================== 子表（设备维修记录行） ====================

  // 获得设备维修记录行列表
  getDvRepairLineListByRepairId: async (repairId) => {
    return await request.get({ url: `/mes/dv-repair/dv-repair-line/list-by-repair-id?repairId=` + repairId })
  },

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

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