import { defHttp } from '/@/utils/http/axios';
import {
  CommonRowModel,
  GroupModel,
  AddConfigInfoParams,
  // EditConfigInfoParams,
  DeleteConfigInfoParams,
  ConfigNameParams,
  configNameExistModel,
} from './model/generalModel';

enum Api {
  GroupUrl = '/general/group/', // 系统配置分组
  ConfigUrl = '/general/config/', // 系统配置表
  FileUrl = '/general/file/', // 上传文件
  ConfigNameExistUrl = '/general/exist', // 检测变量名是否已经存在
  AttachmentUrl = '/general/attachment/', // 检测变量名是否已经存在
}

/**
 * @description: 获取系统配置分组
 */
export function getConfigGroup() {
  return defHttp.request<GroupModel>({
    url: Api.GroupUrl,
    method: 'GET',
  });
}

/**
 * @description: 获取系统配置表
 */
export function getConfigInfo() {
  return defHttp.request<CommonRowModel>({
    url: Api.ConfigUrl,
    method: 'GET',
  });
}
/**
 * @description: 获取系统配置表
 */
export function addConfigInfo(params: AddConfigInfoParams) {
  return defHttp.request<CommonRowModel>({
    url: Api.ConfigUrl,
    method: 'POST',
    params,
  });
}
/**
 * @description: 获取系统配置表
 */
export function editConfigInfo(params) {
  return defHttp.request<CommonRowModel>({
    url: Api.ConfigUrl,
    method: 'PUT',
    params,
  });
}
/**
 * @description: 删除系统配置 id
 */
export function deleteConfigInfo(params: DeleteConfigInfoParams) {
  return defHttp.request<CommonRowModel>({
    url: Api.ConfigUrl + params.id,
    method: 'DELETE',
  });
}

/**
 * @description: 检测变量名是否已经存在
 */
export function configNameExist(params: ConfigNameParams) {
  return defHttp.request<configNameExistModel>({
    url: Api.ConfigNameExistUrl,
    method: 'POST',
    params,
  });
}

/**
 * @description: 获取附件列表
 */
export function getAttachmentList() {
  return defHttp.request<CommonRowModel>({
    url: Api.AttachmentUrl,
    method: 'GET',
  });
}
