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

import type {PackCatalog,PackCatalogQuery}  from '@/types/base/PackCatalog'

const contextPath = '/base/PackCatalog'

// 查询包装种类目录列表
export async function getList(query: PackCatalogQuery): Promise<Result<PageInfo<PackCatalog>>> {
  const res: AxiosResponse<Result<PageInfo<PackCatalog>>> = await request.post(`${contextPath}/get-list`, query)
  return res.data
}

// 获取包装种类目录详情
export async function getDetail(ID: string): Promise<Result<PackCatalog>> {
  const res: AxiosResponse<Result<PackCatalog>> = await request.get(`${contextPath}/get-detail?ID=${ID}`)
  return res.data
}

// 新增包装种类目录
export async function insert(row: PackCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/insert-packCatalog`, row)
  return res.data
}

// 更新包装种类目录
export async function update(row: PackCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-packCatalog`, row)
  return res.data
}

// 删除包装种类目录
export async function remove(packCatalogs: string | string[]): Promise<Result<number>> {
  // 统一转换为数组格式
  const ids = Array.isArray(packCatalogs) ? packCatalogs : [packCatalogs];
  const res: AxiosResponse<Result<number>> = await request.post(
          `${contextPath}/delete-packCatalog?ids`,ids
  )
  return res.data
}
