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

export interface ConfigFields {
  searchValue: string;
  createBy: string;
  createTime: string;
  updateBy: string;
  updateTime: string;
  remark: string;
  params: Record<string, any>;
  beginTime: string;
  endTime: string;
  configId: number;
  configName: string;
  configKey: string;
  configValue: string;
  configType: string;
  moduleFirst: string;
  appId: string;
  appName: string;
}

interface GetListProps extends _Pager_Params, ConfigFields {}

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

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

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

export const addApi = async (data: Partial<Omit<ConfigFields, 'configId'>>) => {
  return await request<Result>({
    url: '/config',
    method: 'post',
    data,
  });
};
// 导出
export const exportExcelApi = async (data: Partial<ConfigFields>) => {
  return await downloadExcelRequest(
    { url: '/config/export', method: 'post', data },
    '参数设置列表',
  );
};
