import type { AxiosResponse } from 'axios'
import type { PageInfo, Result, TypeDescriptor } from '@cacp/ui'
import request from '@/utils/request'
import type { DictDataInfo, DictDataQuery } from '@/types/system/dictData'
import type { AjaxResult } from '@/types/system/dictType'
const contextPath = '/dictData'

// 查询字典数据列表
export async function listData(query: DictDataQuery): Promise<Result<PageInfo<DictDataInfo>>> {
  const res: AxiosResponse<Result<PageInfo<DictDataInfo>>> = await request.post(`${contextPath}/list`, query )
  return res.data
}

// 查询字典数据详细
export async function getData(dictCode: number): Promise<Result<DictDataInfo>> {
  const res: AxiosResponse<Result<DictDataInfo>> = await request.get(`${contextPath}/${dictCode}`)
  return res.data
}

// 根据字典类型查询字典数据信息
export async function getDicts(dictType: string): Promise<AjaxResult<DictDataInfo[]>> {
  const res: AxiosResponse<AjaxResult<DictDataInfo[]>> = await request.get(`${contextPath}/type/${dictType}`)
  return res.data
}

// 新增字典数据
export async function addData(data: DictDataInfo): Promise<AjaxResult<string>> {
  const res: AxiosResponse<AjaxResult<string>> = await request.post(contextPath, data)
  return res.data
}

// 修改字典数据
export async function updateData(data: DictDataInfo): Promise<AjaxResult<string>> {
  const res: AxiosResponse<AjaxResult<string>> = await request.put(contextPath, data)
  return res.data
}

// 删除字典数据
export async function delData(dictCode: number[]): Promise<AjaxResult<string>> {
  const res: AxiosResponse<AjaxResult<string>> = await request.delete(`${contextPath}/${dictCode}`)
  return res.data
}
