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

enum Api {
  CreateWx = '/wechat-api/wx/create',
  UpdateWx = '/wechat-api/wx/update',
  GetWxList = '/wechat-api/wx/list',
  DeleteWx = '/wechat-api/wx/delete',
  GetWxById = '/wechat-api/wx',
}

/**
 * @description: Get wx list
 */

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

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

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

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

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