import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { EmailtempVO, EmailtempForm, EmailtempQuery } from '@/api/msg/emailtemp/types';
import { AttachmentEmailQuery, AttachmentEmailVO } from '@/api/msg/attachmentEmail/types';
import { TemplateInfoQuery, TemplateInfoVO } from '@/api/print/template/templateInfotypes';

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

export const listEmailtemp = (query?: EmailtempQuery): AxiosPromise<EmailtempVO[]> => {
  return request({
    url: '/msg/emailtemp/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询邮件模板
 */
export const queryEmailTemplateList = (sign: string) => {
  const data = {
    sign
  };
  return request({
    url: '/msg/emailtemp/queryTemplateList',
    method: 'post',
    data: data
  });
};

export const getSelectTempCode = (templateCode: string): AxiosPromise<EmailtempVO> => {
  const data = {
    templateCode
  };
  return request({
    url: '/msg/emailtemp/selectTempByTempCode',
    method: 'post',
    data: data
  });
};

/**
 * 查询消息模板配置详细
 * @param templateId
 */
export const getEmailtemp = (templateId: string | number): AxiosPromise<EmailtempVO> => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/emailtemp/getEmailtemp',
    method: 'post',
    data: data
  });
};

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

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

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

export const attachmentList = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/emailtemp/attachmentList',
    method: 'post',
    data: data
  });
};

export const editStatusEmailtemp = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/emailtemp/editStatus',
    method: 'post',
    data: data
  });
};

export const editParamsParsingtemp = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/emailtemp/paramsParsing',
    method: 'post',
    data: data
  });
};

export const queryControlVersionList = (query?: EmailtempQuery): AxiosPromise<EmailtempVO[]> => {
  return request({
    url: '/msg/emailtemp/queryControlVersionList',
    method: 'get',
    params: query
  });
};

export const changeTemplateVersionStatus = (templateId: string | number, versionEnableStatus: string) => {
  const data = {
    templateId,
    versionEnableStatus
  };
  return request({
    url: '/msg/emailtemp/changeTemplateVersionStatus',
    method: 'post',
    data: data
  });
};

export const uploadTempFile = (ossId: string, templateId: string | number, attachmentType: string) => {
  const data = {
    ossId,
    templateId,
    attachmentType
  };
  return request({
    url: '/msg/emailtemp/uploadTempFile',
    method: 'post',
    data: data
  });
};

export const getDownloadAttType = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/msg/emailtemp/getDownloadAttType',
    method: 'post',
    data: data
  });
};

export const deleteFile = (attachmentId: string | number) => {
  const data = {
    attachmentId
  };
  return request({
    url: '/msg/emailtemp/deleteFile',
    method: 'post',
    data: data
  });
};

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

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