import axios from 'axios';
import { getFormData } from '../../third-party/form-data.mjs';
import { getAuthOfTai } from '../auth/auth.mjs';
import '../../nodejs/crypto.mjs';

function sendEmailByTai(_ref) {
  var prefix = _ref.prefix,
    paasId = _ref.paasId,
    paasToken = _ref.paasToken,
    from = _ref.from,
    to = _ref.to,
    title = _ref.title,
    content = _ref.content,
    cc = _ref.cc,
    bcc = _ref.bcc,
    emailType = _ref.emailType,
    bodyFormat = _ref.bodyFormat,
    priority = _ref.priority;
  var FormData = getFormData();
  var headers = getAuthOfTai({
    paasId: paasId,
    paasToken: paasToken
  });
  return new Promise(function (resolve, reject) {
    var formData = new FormData();
    formData.append('From', from);
    formData.append('CC', cc || '');
    formData.append('Bcc', bcc || '');
    formData.append('Title', title || '');
    formData.append('EmailType', emailType);
    formData.append('BodyFormat', bodyFormat);
    formData.append('Priority', priority);
    formData.append('To', to);
    formData.append('Content', content);
    axios({
      headers: Object.assign(Object.assign({}, headers), {
        'Content-Type': "multipart/form-data; charset=utf-8; boundary=\"".concat(formData.getBoundary(), "\"")
      }),
      method: 'POST',
      url: "".concat(prefix, "/ebus/tof4_msg/api/v1/Message/SendMail"),
      data: {
        From: from,
        To: to,
        Title: title,
        Content: content,
        CC: cc,
        Bcc: bcc,
        // 指定邮件类型，默认1。0：外部邮件； 1：内部邮件(内部邮件收件人只能是@tencent.com邮箱，
        // 外部邮件则不会对收件人进行校验) 注：内外邮件同时发送选择类型 0 即可
        EmailType: emailType,
        BodyFormat: bodyFormat,
        Priority: priority // 指定优先级，默认0。（-1:低 0:普通 1:高）
      }
    }).then(function (res) {
      resolve(res.data);
    })["catch"](function (err) {
      reject(err);
    });
  });
}

export { sendEmailByTai };
