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

// 基础主数据--工序表 类型定义
export interface BasicProcessPlan {
  id?: number

  name?:  string

  code?:  string

  sort?: number

  procurement?: number

  outsource?: number

  qualityInspection?: number

  storageEntry?: number

  workCenterName?:  string

  departmentName?:  string

  operDescription?:  string

  createBy?: number

  createTime?:  string

  status?:number

}

// 基础主数据--工序表 API
export const basicProcessPlanApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number; name?:  string }) {
    return request({ url: '/biz/basicProcessPlan/page', method: 'get', params })
  },

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

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

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

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

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

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

  //获取分页列表
  list(params:any) {
    return request({
      url:"/biz/basicProcessPlan/list",
      method:"get",
      params
    })
  }
}