import { request } from '@/service/request';

// 获取字典列表
export function fetchGetDictList<T>(params?: Api.SystemManage.DictSearchParams) {
  return request<T>({
    url: '/system/dict/type/list',
    method: 'get',
    params
  });
}
// 获取字典详情
export function fetchGetDict(dictId: string | number) {
  return request<Api.SystemManage.Dict>({
    url: `/system/dict/type/${dictId}`,
    method: 'get'
  });
}
// 新增字典
export function fetchAddDict(data: Api.SystemManage.Dict) {
  return request({
    url: '/system/dict/type',
    method: 'post',
    data
  });
}
// 修改字典
export function fetchEditDict(data: Api.SystemManage.Dict) {
  return request({
    url: '/system/dict/type',
    method: 'put',
    data
  });
}
// 删除字典
export function fetchDeleteDict(dictIds: string[]) {
  return request({
    url: `/system/dict/type/${dictIds}`,
    method: 'delete'
  });
}

// 查询字典数据列表
export function fetchGetDictDataList(params?: Api.SystemManage.DictInfoSearchParams) {
  return request<Api.SystemManage.DictInfoList>({
    url: '/system/dict/data/list',
    method: 'get',
    params
  });
}

// 查询字典数据详细
export function getData(dictCode: Api.SystemManage.DictInfo['dictCode']) {
  return request<Api.SystemManage.DictInfo>({
    url: `/system/dict/data/${dictCode}`,
    method: 'get'
  });
}

// 根据字典类型查询字典数据信息
export function getDicts(dictType: Api.SystemManage.DictInfo['dictType']) {
  return request<Api.SystemManage.DictInfo[]>({
    url: `/system/dict/data/type/${dictType}`,
    method: 'get'
  });
}

// 新增字典数据
export function addData(data: Api.SystemManage.DictInfo) {
  return request({
    url: '/system/dict/data',
    method: 'post',
    data
  });
}

// 修改字典数据
export function updateData(data: Api.SystemManage.DictInfo) {
  return request({
    url: '/system/dict/data',
    method: 'put',
    data
  });
}

// 删除字典数据
export function delData(dictCode: Api.SystemManage.DictInfo['dictCode'][]) {
  return request({
    url: `/system/dict/data/${dictCode}`,
    method: 'delete'
  });
}
