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

// 设备采集 类型定义
export interface DeviceGather {
  id?: number

  deviceId?: number

  assingWorkId?: number

  userId?: number

  gatherNum?: number

  gatherTime?:  string

}

// 设备采集 API
export const deviceGatherApi = {
  // 分页查询
  page(params: { page: number; pageSize: number }) {
    return request({ url: '/biz/deviceGather/page', method: 'get', params })
  },

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

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

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

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

  // 导出
  export(params?: { ids?:  string[] }) {
    const p: Record<string, any> = {}
    if (params?.ids?.length) p.ids = params.ids.join(',')
    return request({ url: `/biz/deviceGather/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/deviceGather/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

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