import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MestempVO, MestempForm, MestempQuery } from '@/api/msg/mestemp/types';

/**
 * 查询消息模板配置列表
 * @param query
 * @returns {*}
 */

export const listMestemp = (query?: MestempQuery): AxiosPromise<MestempVO[]> => {
  return request({
    url: '/msg/mestemp/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询消息模板配置详细
 * @param templateId
 */
export const getMestemp = (templateId: string | number): AxiosPromise<MestempVO> => {
  return request({
    url: '/msg/mestemp/' + templateId,
    method: 'get'
  });
};

/**
 * 新增消息模板配置
 * @param data
 */
export const addMestemp = (data: MestempForm) => {
  return request({
    url: '/msg/mestemp/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改消息模板配置
 * @param data
 */
export const updateMestemp = (data: MestempForm) => {
  return request({
    url: '/msg/mestemp/updateMestemp',
    method: 'post',
    data: data
  });
};

/**
 * 删除消息模板配置
 * @param templateId
 */
export const delMestemp = (templateId: string | number | Array<string | number>) => {
  return request({
    url: '/msg/mestemp/' + templateId,
    method: 'delete'
  });
};

export const getStatusLog = (params: any) => {
  return request({
    url: '/msg/mestemp/statuslog',
    method: 'post',
    data: params
  });
};
export const getAuditHistory = (data) => {
  return request({
    url: '/msg/version/getAuditLogs',
    method: 'post',
    data: data
  });
};

export const getChannelLog = (params: any) => {
  return request({
    url: '/msg/mestemp/channellog',
    method: 'post',
    data: params
  });
};
export const editStatusMsgtemp = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/mestemp/confirm',
    method: 'post',
    data: data
  });
};

export const queryMSMTemplateList = (sign: string) => {
  const data = {
    sign
  };
  return request({
    url: '/msg/mestemp/queryTemplateList',
    method: 'POST',
    data: data
  });
};

export const selectMSMTempByTempCode = (data) => {
  return request({
    url: '/msg/mestemp/selectMSMTempByTempCode',
    method: 'post',
    data: data
  });
};

export const selectMSMTempByTempCodeByCodeAndVersion = (templateCode, versionNumber) => {
  const data = {
    templateCode,
    versionNumber
  };
  return request({
    url: '/msg/mestemp/selectMSMTempByTempCode',
    method: 'post',
    data: data
  });
};

/**
 * 获取风控列表
 * @param query
 * @returns {*}
 */

export const getRiskControlList = () => {
  return request({
    url: '/msg/riskStrategyParam/getRiskList',
    method: 'post'
  });
};

/**
 * 获取归属模块的枚举值
 */

export const constructModuleEnumTree = () => {
  return request({
    url: '/msg/mestemp/constructModuleEnumTree',
    method: 'post'
  });
};

export const queryTemplateRiskControl = (templateId) => {
  return request({
    url: '/msg/templateRiskControl/' + templateId,
    method: 'get'
  });
};
