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

// 工位交接记录表 类型定义
export interface StationHandover {
  id?: number

  deviceId?: number

  stationId?: number

  handoverPersonId?:  number

  receiverPersonId?:  number

  handoverTime?:  string

  remark?:  string

  createTime?:  string

  createBy?:  string

}

// 工位交接记录表 API
export const stationHandoverApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; deviceIds?: string }) {
    return request({ url: '/biz/stationHandover/page', method: 'get', params })
  },

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

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

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

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

  // 导出
  export(params?: { ids?: number[]; 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/stationHandover/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/stationHandover/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

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