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

// 流转记录表 类型定义
export interface FlowingAround {
  id?: number

  currentlyPrefaceId?: number
  currentlyPrefaceName?: string

  nextPrefaceId?: number
  nextPrefaceName?: string

  businessId?: number

  businessCode?:  string
  businessName?:  string
  
  flowingAroundType?: number
  quantity?: number

  confirmUserId?: number
  confirmUserName?:  string

  confirmTime?:  string
  confirmResult?: string

  submitter?: number
  submitterName?:  string

  submitTime?:  string
  reason?: string

}

// 流转记录表 API
export const flowingAroundApi = {
  // 分页查询
  page(params: { page: number; pageSize: number }) {
    return request({ url: '/biz/flowingAround/page', method: 'get', params })
  },

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

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

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

  // 删除
  delete(ids:  string[]) {
    return request({ url: `/biz/flowingAround/${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/flowingAround/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/flowingAround/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

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