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

/** 获取表格数据 */
export const getRepDataSourceListApi = (data: any) => {
  return request.postJson({ url: '/param/spi/param/RepDataSource/RepDataSourceQueryPage', data });
};

/** 批量删除 */
export const delRepDataSourceListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      dsCode: v,
    };
  });
  return request.postJson({
    url: '/param/spi/param/RepDataSource/RepDataSourceBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delRepDataSourceApi = (dscode: string | number): Promise<IResponse> => {
  return request.postJson({
    url: '/param/spi/param/RepDataSource/RepDataSourceDelete',
    data: { dscode },
  });
};

/** 保存 */
export const saveRepDataSourceApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.postJson({ url: '/param/spi/param/RepDataSource/RepDataSourceSave', data });
};

/** 查询单条数据 */
export const queryRepDataSourceApi = (dscode: string | number): Promise<IResponse> => {
  return request.postJson({
    url: '/param/spi/param/RepDataSource/RepDataSourceQueryOne',
    data: { dscode },
  });
};

/** 导入 */
export const importExcelApiUrl = '/param/sui/param/RepDataSource/RepDataSourceImportExcel';

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

/** 测试链接 */
export const checkConnectApi = (params: any) => {
  return request.postJson({ url: '/param/spi/param/RepDataSource/DataSourceCheckConnect', data: params });
};
