import type { AxiosResponse } from 'axios'
import type { PageInfo, Result } from '@cacp/ui'
import request from '@/utils/request'

import type {EntryHead,EntryHeadQuery}  from '@/types/analyze/EntryHead'

const contextPath = '/analyze/EntryHead'

// 查询危险品报关单头列表
export async function getList(query: EntryHeadQuery): Promise<Result<PageInfo<EntryHead>>> {
  const res: AxiosResponse<Result<PageInfo<EntryHead>>> = await request.post(`${contextPath}/get-list`, query)
  return res.data
}

// 获取采购入库单详情
export async function getDetail(entryId: string): Promise<Result<EntryHead>> {
  const res: AxiosResponse<Result<EntryHead>> = await request.get(`${contextPath}/get-detail?entryId=${entryId}`)
  return res.data
}

// 新增采购入库单
export async function insert(row: EntryHead): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/insert-entryHead`, row)
  return res.data
}

// 更新采购入库单
export async function update(row: EntryHead): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-entryHead`, row)
  return res.data
}

// 删除采购入库单
export async function remove(entryHeads: string | string[]): Promise<Result<number>> {
  // 统一转换为数组格式
  const ids = Array.isArray(entryHeads) ? entryHeads : [entryHeads];
  const res: AxiosResponse<Result<number>> = await request.post(
          `${contextPath}/delete-entryHead?ids`,ids
  )
  return res.data
}
