package com.jeequan.jeepay.core.model.smsconfig;

import com.alibaba.fastjson.JSON;
import com.jeequan.jeepay.core.constants.CS;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.regex.Pattern;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AbstractSmsConfig {

    public static AbstractSmsConfig getSmsConfig(String smsProvideKey, String configVal){

        if(CS.SMS_PROVIDER_TYPE_API_ENUM.SMS_PROVIDE_KEY_ALIYUNDY.equals(smsProvideKey)){
            return JSON.parseObject(configVal, AliyundySmsConfig.class);
        }

        if(CS.SMS_PROVIDER_TYPE_API_ENUM.SMS_PROVIDE_KEY_JEEPAYDX.equals(smsProvideKey)){
            return JSON.parseObject(configVal, JeepaydxSmsConfig.class);
        }

        if (CS.SMS_PROVIDER_TYPE_API_ENUM.SMS_PROVIDE_KEY_JUHEDX.equals(smsProvideKey)) {
            return JSON.parseObject(configVal, JuhedxSmsConfig.class);
        }

        if(CS.SMS_PROVIDER_TYPE_API_ENUM.SMS_PROVIDE_KEY_MOCKTEST.equals(smsProvideKey)){
            return JSON.parseObject(configVal, MocktestSmsConfig.class);
        }

        return null;
    }


    /**
     * 验证手机号码，11位数字，1开头 *
     * @param mobileNumber
     * @return
     */
    public static boolean checkMobileNumber(String mobileNumber) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile("^1\\d{10}$");
            flag = regex.matcher(mobileNumber).matches();
        } catch (Exception ignored) {

        }
        return flag;
    }

}
