import helper from 'src/Utils/helper';
import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  SysConfigSearchEntity,
  SysConfigNameOrKeySearchEntity,
  SysConfigEntity
} from './model/sysConfig';
const pathName = 'SysConfig/';

class SysConfigApi {
  // 获取系统参数设置分页列表
  getSysConfigPageList = (val: Pagination<SysConfigSearchEntity>) => {
    let format = `?page=${val.page}&size=${val.rowsPerPage}`;
    if (val.data.configName) {
      format += `&configName=${val.data.configName}`;
    }
    if (val.data.configKey) {
      format += `&configKey=${val.data.configKey}`;
    }
    return request.get(`${pathName}GetSysConfigPageList${format}`);
  };

  // 获取系统参数列表
  getSysConfigList = (val: SysConfigSearchEntity) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetSysConfigList${format}`);
  };

  // 根据 id 获取系统参数明细
  getSysConfigDetailById = (id: any) => {
    return request.get(`${pathName}GetSysConfigDetailById?id=${id}`);
  };

  // 根据 name、key 获取系统参数设置明细
  getSysConfigDetailNameOrKey = (val: SysConfigNameOrKeySearchEntity) => {
    const format = helper.params(val);
    return request.get(`${pathName}GetSysConfigDetailNameOrKey${format}`);
  };

  // 添加
  add = (val: SysConfigEntity) => {
    return request.post(`${pathName}AddSysConfig`, val);
  };

  // 修改
  edit = (val: SysConfigEntity) => {
    return request.post(`${pathName}UpdateSysConfig`, val);
  };

  // 删除
  delete = (id: any) => {
    return request.post(`${pathName}DeleteSysConfig?id=${id}`);
  };
}
const sysConfigApi = new SysConfigApi();

export { sysConfigApi };
