package ink.wgink.module.sms.factory.sms;

import ink.wgink.exceptions.base.SystemException;
import ink.wgink.module.sms.factory.sms.impl.DefaultSmsSendImpl;
import ink.wgink.module.sms.factory.sms.impl.TencentSmsSendImpl;
import ink.wgink.properties.sms.SmsProperties;
import org.apache.commons.lang3.StringUtils;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: SendFactory
 * @Description: 短信工厂
 * @Author: wanggeng
 * @Date: 2021/5/1 4:14 下午
 * @Version: 1.0
 */
public class SmsSendFactory {

    /**
     * 腾讯类别
     */
    public static String TENCENT_TYPE = "tencent";
    /**
     * 自定义类别
     */
    public static String CUSTOM_TYPE = "custom";

    /**
     * 默认发送短信
     *
     * @param smsProperties
     * @return
     */
    public static ISmsSend getSendSms(SmsProperties smsProperties, ICustomSmsSend smsCustomSend) {
        if (!smsProperties.getActive()) {
            throw new SystemException("短信配置未激活");
        }
        if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) {
            return new TencentSmsSendImpl(smsProperties.getTencentSms());
        } else if (StringUtils.equals(CUSTOM_TYPE, smsProperties.getType())) {
            if (smsCustomSend == null) {
                throw new SystemException("自定义发送短信类不存在");
            }
            return smsCustomSend;
        }
        return new DefaultSmsSendImpl(smsProperties.getDefaultSms());
    }

}
