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

import type {GoodsCatalog,GoodsCatalogQuery}  from '@/types/base/GoodsCatalog'

const contextPath = '/base/GoodsCatalog'

// 查询基础数据-危险货物目录列表
export async function getList(query: GoodsCatalogQuery): Promise<Result<PageInfo<GoodsCatalog>>> {
  const res: AxiosResponse<Result<PageInfo<GoodsCatalog>>> = await request.post(`${contextPath}/get-list`, query)
  return res.data
}

// 获取基础数据-危险货物目录详情
export async function getDetail(ID: string): Promise<Result<GoodsCatalog>> {
  const res: AxiosResponse<Result<GoodsCatalog>> = await request.get(`${contextPath}/get-detail?ID=${ID}`)
  return res.data
}

// 新增基础数据-危险货物目录
export async function insert(row: GoodsCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/insert-goodsCatalog`, row)
  return res.data
}

// 更新基础数据-危险货物目录
export async function update(row: GoodsCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-goodsCatalog`, row)
  return res.data
}

// 删除基础数据-危险货物目录
export async function remove(goodsCatalogs: string | string[]): Promise<Result<number>> {
  // 统一转换为数组格式
  const ids = Array.isArray(goodsCatalogs) ? goodsCatalogs : [goodsCatalogs];
  const res: AxiosResponse<Result<number>> = await request.post(
          `${contextPath}/delete-goodsCatalog?ids`,ids
  )
  return res.data
}
