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

// AssingWorkDetail 类型定义
export interface AssingWorkDetail {
  id?: number

  assingWorkId?: number

  userId?: number

  deviceId?: number

  num?: number

  source?: number

  createTime?:  string

}

// AssingWorkDetail API
export const assingWorkDetailApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number }) {
    return request({ url: '/biz/assingWorkDetail/page', method: 'get', params })
  },

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

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

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

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

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

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


  //根据派工id获取详情信息
  selectAssingWorkDetailListByAssingWorkId(assingWorkId:number) {
    return request({
        url:`/biz/assingWorkDetail/getAssingWorkDetailList/${assingWorkId}`,
        method:"get"
    })
  }
}