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

// 工艺路线工序明细 类型定义
export interface ProcessRouteStep {
  id?: number

  routeId?: number

  operNumber?: number

  processName?:  string

  operDescription?:  string

  workCenterName?:  string

  departmentName?:  string

  activityUnit?:  string

  optCtrlCodeName?:  string

  activityQty?:  string

  sort?: number

  isOutsource?: number

  status?: number

  createTime?:  string

  changeTime?:  string

  isBind?: boolean

}

// 工艺路线工序明细 API
export const processRouteStepApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number; status?: number }) {
    return request({ url: '/biz/processRouteStep/page', method: 'get', params })
  },


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

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

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

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

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

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

  list(params:{id:number}) {
    return request({
      url:"/biz/processRouteStep/list",
      method:'get',
      params
    })
  }
}
