import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import { BaseDataResp, BaseListReq, BaseResp, BaseIDsReq, BaseIDReq } from '@/api/model/baseModel';
import { ServerInfo, ServerListResp } from './model/serverModel';

enum Api {
  CreateServer = '/wechat-api/server/create',
  UpdateServer = '/wechat-api/server/update',
  GetServerList = '/wechat-api/server/list',
  DeleteServer = '/wechat-api/server/delete',
  GetServerById = '/wechat-api/server',
}

/**
 * @description: Get server list
 */

export const getServerList = (params: BaseListReq, mode: ErrorMessageMode = 'notice') => {
  return defHttp.post<BaseDataResp<ServerListResp>>(
    { url: Api.GetServerList, params },
    { errorMessageMode: mode },
  );
};

/**
 *  @description: Create a new server
 */
export const createServer = (params: ServerInfo, mode: ErrorMessageMode = 'notice') => {
  return defHttp.post<BaseResp>(
    { url: Api.CreateServer, params: params },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    },
  );
};

/**
 *  @description: Update the server
 */
export const updateServer = (params: ServerInfo, mode: ErrorMessageMode = 'notice') => {
  return defHttp.post<BaseResp>(
    { url: Api.UpdateServer, params: params },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    },
  );
};

/**
 *  @description: Delete servers
 */
export const deleteServer = (params: BaseIDsReq, mode: ErrorMessageMode = 'notice') => {
  return defHttp.post<BaseResp>(
    { url: Api.DeleteServer, params: params },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    },
  );
};

/**
 *  @description: Get server By ID
 */
export const getServerById = (params: BaseIDReq, mode: ErrorMessageMode = 'notice') => {
  return defHttp.post<BaseDataResp<ServerInfo>>(
    { url: Api.GetServerById, params: params },
    {
      errorMessageMode: mode,
    },
  );
};
