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

// 质检项和工序关联表 类型定义
export interface QcitemProcess {
  id?: number

  qcItemId?: number

  processId?: number

  page?:number

  pageSize?:number
}

// 质检项和工序关联表 API
export const qcitemProcessApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number }) {
    return request({ url: '/biz/qcitemProcess/page', method: 'get', params })
  },

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

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

    //质检项关联
  qualityItemcreate(data: QcitemProcess) {
    return request({ url: '/biz/qcitemProcess/create', method: 'post', data })
  },

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

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

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


}