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

export interface Tool {
  id?: number
  toolCode: string
  toolName: string
  toolType: string
  toolTypeId?: number
  specModel: string
  material: string
  manufacturer: string
  purchaseDate?: string | number
  lifeCycle: number
  usedCount?: number
  status: number
  remark: string
  createTime?: string
  updateTime?: string
}

export const toolApi = {
  page(params: {
    page: number
    pageSize: number
    toolCode?: string
    toolName?: string
    status?: number
  }) {
    return request({
      url: '/biz/tool/page',
      method: 'get',
      params
    })
  },

  create(data: Tool) {
    return request({
      url: '/biz/tool',
      method: 'post',
      data
    })
  },

  update(data: Tool) {
    return request({
      url: '/biz/tool',
      method: 'put',
      data
    })
  },

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

  export(params?: {
    ids?: number[]
    toolCode?: string
    toolName?: string
    status?: number
  }) {
    const p: Record<string, any> = {}
    if (params?.ids?.length) p.ids = params.ids.join(',')
    if (params?.toolCode) p.toolCode = params.toolCode
    if (params?.toolName) p.toolName = params.toolName
    if (params?.status != null) p.status = params.status
    return request({
      url: '/biz/tool/report',
      method: 'get',
      params: p,
      responseType: 'blob'
    })
  }
}