package cn.axzo.msg.center.notices.manager;

import cn.axzo.msg.center.notices.integration.client.impl.AliYunSmsClientImpl;
import cn.axzo.msg.center.notices.integration.dto.request.SendSmsCommonRequest;
import cn.axzo.msg.center.notices.integration.dto.response.SendSmsCommonResponse;
import cn.axzo.msg.center.notices.manager.api.SmsSendManager;
import cn.axzo.msg.center.notices.manager.api.dto.request.BatchMessageSendRequestDto;
import cn.axzo.msg.center.notices.manager.api.dto.request.MessageSendRequestDto;
import cn.axzo.msg.center.notices.manager.api.dto.response.BatchMessageSendResponseDto;
import cn.axzo.msg.center.notices.manager.api.dto.response.SendSmsCommonResponseDto;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * sms服务
 *
 * @Author: LiuYang
 * @Date: 2021/5/25 16:04
 */
@Slf4j
@Service("aliyunSmsSendManager")
public class AliyunSmsSendManagerImpl implements SmsSendManager {

  @Resource
  private AliYunSmsClientImpl aliyunSmsService;

  @Override
  public SendSmsCommonResponseDto sendMessage(MessageSendRequestDto requestDto) {
    log.info("[AliyunSmsSendManagerImpl#sendMessage] -> aliyun - 发送sms {}", JSON.toJSONString(requestDto));
    // 请求转换
    SendSmsCommonRequest request = new SendSmsCommonRequest();
    request.setPhoneNo(requestDto.getPhoneNo());
    request.setTemplateCode(requestDto.getTemplateNo());
    request.setTemplateMap(requestDto.getTemplateMap());
    request.setRequestChannelNo(requestDto.getRequestChannelNo());

    // 发送短信
    SendSmsCommonResponse response = aliyunSmsService.sendSms(request);

    // 响应请求
    SendSmsCommonResponseDto result = new SendSmsCommonResponseDto();
    result.setBizId(response.getBizId());
    result.setRequestId(response.getRequestId());
    result.setMessage(result.getMessage());
    return result;
  }

  @Override
  public BatchMessageSendResponseDto sendBatchMessage(BatchMessageSendRequestDto requestDto) {
    throw new UnsupportedOperationException();
  }

}
