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

enum Api {
  CreateContact = '/wechat-api/contact/create',
  UpdateContact = '/wechat-api/contact/update',
  GetContactList = '/wechat-api/contact/list',
  DeleteContact = '/wechat-api/contact/delete',
  GetContactById = '/wechat-api/contact',
}

/**
 * @description: Get contact list
 */

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

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

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

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

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