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

import cn.axzo.msg.center.notices.common.enums.MessageCommonStatusEnum;
import cn.axzo.msg.center.notices.integration.client.SubMailClient;
import cn.axzo.msg.center.notices.integration.dto.request.SendSmsCommonRequest;
import cn.axzo.msg.center.notices.integration.dto.response.SubMailSingleSendSmsResponse;
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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @description xxx
 * @author cold_blade
 * @date 2023/9/6
 * @version 1.0
 */
@Slf4j
@RequiredArgsConstructor
@Component("subMailSmsSendManager")
public class SubMailSmsSendManagerImpl implements SmsSendManager {

    private final SubMailClient subMailClient;

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

        // 发送短信
        SubMailSingleSendSmsResponse response = subMailClient.sendSingleTemplateSms(request);

        // 响应请求
        SendSmsCommonResponseDto result = new SendSmsCommonResponseDto();
        result.setBizId(response.getSendId());
        result.setRequestId(response.getRequestId());
        result.setMessage(response.getMsg());
        result.setStatus(response.isSuccess() ? MessageCommonStatusEnum.OK : MessageCommonStatusEnum.FAIL);
        return result;
    }

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