package com.engine.recruit.util;

import weaver.common.MessageUtil;
import weaver.email.EmailWorkRunnable;
import weaver.general.Util;

import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/10/13
 * @version: 1.0
 */
public class RecruitMessageUtils {
    public static boolean sendEmail(Map<String, Object> param) {
        String sendTo = Util.null2String(param.get("sendTo"));
        String emailTitle = Util.null2String(param.get("emailTitle"));
        String emailContent = Util.null2String(param.get("emailContent"));
        return sendEmail(sendTo, emailTitle, emailContent);
    }

    public static boolean sendSMS(Map<String, Object> param) {
        String receiver = Util.null2String(param.get("receiver"));
        String content = Util.null2String(param.get("content"));
        return sendSMS(receiver, content);
    }

    public static boolean sendEmail(String sendTo, String emailTitle, String emailContent) {
        return MessageUtil.sendEmail(sendTo, emailTitle, emailContent);
    }

    /**
     * @param sendTo       收件人
     * @param emailTitle   邮件标题
     * @param emailContent 邮件内容
     * @param imageFileIds 邮件附件，imageFile表记录id，多个时英文逗号分隔
     * @return
     */
    public static boolean sendEmailWithFile(String sendTo, String emailTitle, String emailContent, String imageFileIds) {
        EmailWorkRunnable emailWorkRunnable = new EmailWorkRunnable(sendTo, Util.toHtmlMode(emailTitle), Util.toHtmlMode(emailContent));
        emailWorkRunnable.setImagefileids(imageFileIds);
        return emailWorkRunnable.emailCommonRemind();
    }

    public static boolean sendSMS(String receiver, String content) {
        // 去除短信内容中的html样式
        content = content.replaceAll("<[^>]*>|&nbsp;", "").replaceAll("\\n+", "\n");
        return MessageUtil.sendSMS(receiver, content);
    }


}
