/**
 * 
 */
package org.springblade.message.sms;

import org.springblade.message.MsgTemplate;
import org.springblade.message.enums.MsgType;
import org.springblade.message.model.MsgResponse;
import org.springblade.message.model.SmsInfo;
import org.springblade.message.model.SmsMsgRequest;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;

/**
 * @author wookvn
 *
 */
public abstract class SmsMsgTemplate implements MsgTemplate {

	@Override
	public MsgResponse sendSmsMessage(SmsMsgRequest smsMsgRequest) {
		SmsInfo smsInfo = smsMsgRequest.getSmsInfo();
		if(smsInfo == null 
				|| StrUtil.isEmpty(smsInfo.getAccessKey())
				|| StrUtil.isEmpty(smsInfo.getSecretKey())
				|| CollectionUtil.isEmpty(smsMsgRequest.getPhones())
				|| CollectionUtil.isEmpty(smsMsgRequest.getParams())) {
			return MsgResponse.failure("核心参数为空");
		}
		if((smsMsgRequest.getMsgType() == MsgType.smsAliyun || 
				smsMsgRequest.getMsgType() == MsgType.smsTencent)
				&& StrUtil.isBlank(smsInfo.getRegionId())) {
			return MsgResponse.failure("地域不能为空");
		}
		if(smsMsgRequest.getMsgType() == MsgType.smsTencent 
				&& StrUtil.isBlank(smsInfo.getAppId())) {
			return MsgResponse.failure("APPID不能为空");
		}
		return sendMessage(smsMsgRequest);
	}
	
	/**
	 * 发送消息
	 * @param smsMsgRequest
	 * @return
	 */
	public abstract MsgResponse sendMessage(SmsMsgRequest smsMsgRequest);
	
	/**
	 * 查询短信模版内容
	 * @param smsInfo
	 * @return
	 */
	public abstract MsgResponse queryTemplateContent(SmsInfo smsInfo);
}
