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

import type {NewDeclaredGoods,NewDeclaredGoodsQuery}  from '@/types/analyze/NewDeclaredGoods'

const contextPath = '/analyze/NewDeclaredGoods'

// 查询新申报商品提示列表
export async function getList(query: NewDeclaredGoodsQuery): Promise<Result<PageInfo<NewDeclaredGoods>>> {
  console.log(query)
  const res: AxiosResponse<Result<PageInfo<NewDeclaredGoods>>> = await request.post(`${contextPath}/get-list`, query)
  return res.data
}

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

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

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

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