import request, { downloadExcelRequest } from '../utils/request';
import { DictTypeFields } from './DictDataController';
import { Result, ResultList, _Pager_Params } from './types';

interface GetListProps extends _Pager_Params, DictTypeFields {}

export const getListApi = async (params?: Partial<GetListProps>) => {
  return request<ResultList<DictTypeFields[]>>({
    url: '/dict/type/list',
    method: 'get',
    params,
  });
};

export const delApi = async (deleteKeys: DictTypeFields['dictId'][]) => {
  const deleteKeysString = deleteKeys.join(',');
  return await request<Result>({
    url: `/dict/type/delete/${deleteKeysString || ''}`,
    method: 'get',
  });
};

export const updateApi = async (data: Partial<DictTypeFields>) => {
  return await request<Result>({
    url: '/dict/type/edit',
    method: 'post',
    data,
  });
};

export const addApi = async (data: Partial<Omit<DictTypeFields, 'dictId'>>) => {
  return await request<Result>({
    url: '/dict/type',
    method: 'post',
    data,
  });
};
// 刷新缓存
export const refreshCacheApi = async () => {
  return await request<Result>({
    url: '/dict/type/refreshCache',
    method: 'get',
  });
};
// 导出
export const exportExcelApi = async (data: Partial<DictTypeFields>) => {
  return await downloadExcelRequest(
    { url: '/dict/type/export', method: 'post', data },
    '字典类型列表',
  );
};

// 导入
export const importExcelApi = async (data: FormData) => {
  return await request<Result>({
    url: '/dict/type/importData',
    method: 'post',
    data,
  });
};
