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

import cn.axzo.msg.center.domain.entity.MNSBatchMessage;
import cn.axzo.msg.center.notices.manager.api.dto.request.BatchMessageSendRequestDto;
import cn.axzo.msg.center.notices.manager.api.dto.request.SmsContentDto;
import com.alibaba.fastjson.JSON;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @Classname ChuangLanBatchMessageRequestDtoConverter
 * @Author: szg
 * @Date: 2021年08月10日 11:51
 * @Description:
 */
@Component
public class ChuangLanBatchMessageRequestDtoConverter implements
    Converter<MNSBatchMessage, BatchMessageSendRequestDto> {

  @Override
  public BatchMessageSendRequestDto convert(MNSBatchMessage source) {
    Assert.notNull(source, "source must not be null");
    BatchMessageSendRequestDto requestDto = new BatchMessageSendRequestDto();
    requestDto.setAppCode(source.getAppNo());
    requestDto.setAppRequestNo(source.getRequestNo());
    requestDto.setRequestChannelNo(source.getMessageOrderNo());
    requestDto.setInnerTemplateNo(source.getTemplateNo());
    requestDto.setBatchNo(source.getBatchNo());
    List<SmsContentDto> dtos = JSON
        .parseArray(source.getSmsContent(), SmsContentDto.class);
    requestDto.setSmsContentDtos(dtos);
    return requestDto;
  }
}
