import { defHttp } from '/@/utils/http/axios';
import {
  MessageConfig,
  MessageConfigParams,
  MessageConfigResult,
  MessageConfigResultModel,
  MessageParams,
} from './model/configModel';

enum MessageConfigApi {
  CONFIG_URL = '/message',
}

/**
 * 获取当前租户下的所有配置
 */
export const findMessageConfig = (params: MessageParams) => {
  return defHttp.post<MessageConfigResult[]>({
    url: MessageConfigApi.CONFIG_URL + '/find',
    params,
  });
};

/**
 * @description: 获取MessageConfig分页数据
 */
export const messageConfigPage = (params: MessageConfigParams) =>
  defHttp.get<MessageConfigResultModel>({
    url: MessageConfigApi.CONFIG_URL,
    params,
  });

/**
 * 更新或保存MessageConfig配置
 * @param params 参数
 * @param isUpdate 是否更新
 */
export const saveOrEditMessageConfig = (params: MessageConfig, isUpdate: boolean) => {
  if (isUpdate) {
    return defHttp.put<MessageConfigResultModel>({
      url: MessageConfigApi.CONFIG_URL,
      params,
    });
  } else {
    return defHttp.post<MessageConfigResultModel>({
      url: MessageConfigApi.CONFIG_URL,
      params,
    });
  }
};

/**
 * 更新配置状态
 * @param id 配置id
 * @param messageType 消息类型
 * @param status 状态
 */
export const setMessageConfigStatus = (
  id: string,
  messageType: string,
  status: number,
  tenantId: string
) =>
  defHttp.put<MessageConfigResultModel>({
    url: MessageConfigApi.CONFIG_URL,
    data: {
      id,
      messageType,
      status,
      tenantId,
    },
  });
/**
 * 删除MessageConfig
 * @param ids 删除id数组
 */
export const deleteMessageConfig = (ids: string[]) =>
  defHttp.delete({
    url: MessageConfigApi.CONFIG_URL,
    data: {
      ids: ids,
    },
  });
