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

import type {ChemicalsCatalog,ChemicalsCatalogQuery}  from '@/types/base/ChemicalsCatalog'

const contextPath = '/base/ChemicalsCatalog'

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

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

// 新增基数数据-危化品目录
export async function insert(row: ChemicalsCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/insert-chemicalsCatalog`, row)
  return res.data
}

// 更新基数数据-危化品目录
export async function update(row: ChemicalsCatalog): Promise<Result<number>> {
  const res: AxiosResponse<Result<number>> = await request.post(`${contextPath}/update-chemicalsCatalog`, row)
  return res.data
}

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