/**
 * KRA - System Params API Service
 */
import request from '@/utils/request';

export interface SysParams {
  ID?: number;
  CreatedAt?: string;
  UpdatedAt?: string;
  name: string;
  key: string;
  value: string;
  desc?: string;
}

/** 创建参数 */
export const createSysParams = (data: SysParams) => {
  return request.post<ApiResponse<any>>('/sysParams/createSysParams', data);
};

/** 删除参数 */
export const deleteSysParams = (params: { ID: number }) => {
  return request.delete<ApiResponse<any>>('/sysParams/deleteSysParams', { params });
};

/** 批量删除参数 */
export const deleteSysParamsByIds = (params: { IDs: number[] }) => {
  return request.delete<ApiResponse<any>>('/sysParams/deleteSysParamsByIds', { params });
};

/** 更新参数 */
export const updateSysParams = (data: SysParams) => {
  return request.put<ApiResponse<any>>('/sysParams/updateSysParams', data);
};

/** 根据ID查询参数 */
export const findSysParams = (params: { ID: number }) => {
  return request.get<ApiResponse<{ resysParams: SysParams }>>('/sysParams/findSysParams', { params });
};

/** 分页获取参数列表 */
export const getSysParamsList = (params: PageParams & { name?: string; key?: string }) => {
  return request.get<ApiResponse<PageResult<SysParams>>>('/sysParams/getSysParamsList', { params });
};

/** 不需要鉴权的参数接口 */
export const getSysParam = (params: { key: string }) => {
  return request.get<ApiResponse<{ sysParams: SysParams }>>('/sysParams/getSysParam', { params });
};

// 别名导出，兼容页面调用
export const getParamsList = getSysParamsList;
export const createParams = createSysParams;
export const updateParams = updateSysParams;
export const deleteParams = deleteSysParams;
export const deleteParamsByIds = deleteSysParamsByIds;
export const findParams = findSysParams;

export default {
  createSysParams,
  deleteSysParams,
  deleteSysParamsByIds,
  updateSysParams,
  findSysParams,
  getSysParamsList,
  getSysParam,
  getParamsList,
  createParams,
  updateParams,
  deleteParams,
  deleteParamsByIds,
  findParams,
};
