import request from '@/config/axios';
import type { TableData } from './types';

/** 获取表格数据 */
export const getCsckBusinessSystemListApi = (data: any) => {
  return request.postJson({ url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemQueryPage', data });
};

/** 批量删除 */
export const delCsckBusinessSystemListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      systemCode: v,
    };
  });
  return request.postJson({
    url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delCsckBusinessSystemApi = (systemCode: string | number, systemVersion: string): Promise<IResponse> => {
  return request.postJson({ url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemDelete', data: { systemCode, systemVersion } });
};

/** 保存 */
export const saveCsckBusinessSystemApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.postJson({ url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemSave', data });
};

/** 查询单条数据 */
export const queryCsckBusinessSystemApi = (systemCode: string | number, systemVersion: string): Promise<IResponse> => {
  return request.postJson({ url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemQueryOne', data: { systemCode, systemVersion } });
};

/** 导入 */
export const importExcelApiUrl = '/csck/sui/csck/CsckBusinessSystem/CsckBusinessSystemImportExcel';

/** 导出 */
export const exportExcelApi = (params: any) => {
  return request.doExport({ url: '/csck/sdi/csck/CsckBusinessSystem/CsckBusinessSystemExportXls', params });
};

/** 获取某个字典 */
export const getCsckBusinessSystemApi = async ({ paramName }: { paramName: string; systemCode?: string }) => {
  const res = await request.post({
    url: '/csck/spi/csck/CsckBusinessSystem/CsckBusinessSystemDict',
    data: { paramName: paramName },
  });
  if (res?.body?.result?.length > 0) {
    return res.body.result.map(item => ({
      label: item.dictName,
      value: item.dictld,
    }));
  }
  return [];
};
