package com.kingdee.eas.custom.sendmessage.utils;

import com.kingdee.bos.BOSException;
import com.kingdee.eas.custom.sendmessage.utils.impl.ElectronicProofTemplate;
import com.kingdee.eas.custom.sendmessage.utils.impl.ResignationNoticeTemplate;
import com.kingdee.util.StringUtils;
import org.apache.log4j.Logger;

import java.util.Properties;

/**
 * 短信模板配置工厂类;
 * 202411
 * @author coyle
 * 如果加了模板请在此配置,实现TemplateStrategy接口添加一个模板类;
 */
public class TemplateStrategyFactory {

    private static Logger logger = Logger.getLogger(TemplateStrategyFactory.class);
    private static Properties propt  ;


    public static TemplateStrategy getTemplateStrategy(String templateId) throws BOSException {
        if (templateId == null || templateId.isEmpty()) {
            throw new IllegalArgumentException("Template ID cannot 模板id没传");
        }
        try {
            Properties propt = GetMessageConfig.getProp();
            logger.error("短信模板id为:" + templateId);
            if (StringUtils.equals(templateId, StringUtils.cnulls(propt.getProperty("proofTemp")))) {
                return new ElectronicProofTemplate();
            } else if (StringUtils.equals(templateId, StringUtils.cnulls(propt.getProperty("resignTemp")))) {
                return new ResignationNoticeTemplate();
            } else {
                throw new IllegalArgumentException("Invalid template ID: " + templateId);
            }
        } catch (Exception e) {
            logger.error("获取模板策略时发生错误: ", e);
            throw new BOSException("获取模板策略失败: " + e.getMessage(), e);
        }
    }

}
