package com.backendsys.modules.sdk.tencentcloud.ems.service.impl;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import com.backendsys.modules.sdk.tencentcloud.ems.dao.TencentEmsCallbackDao;
import com.backendsys.modules.sdk.tencentcloud.ems.entity.TencentEmsCallback;
import com.backendsys.modules.sdk.tencentcloud.ems.entity.TencentEmsCallbackParams;
import com.backendsys.modules.sdk.tencentcloud.ems.service.TencentEmsCallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

@Service
public class TencentEmsCallbackServiceImpl implements TencentEmsCallbackService {
    @Autowired
    private TencentEmsCallbackDao tencentEmsCallbackDao;

    @Override
    public void receiveCallback(TencentEmsCallbackParams tencentEmsCallbackParams) {
        // 构建实体
        TencentEmsCallback entity = new TencentEmsCallback();
        entity.setEvent(tencentEmsCallbackParams.getEvent());
        entity.setEmail(tencentEmsCallbackParams.getEmail());
        entity.setBulk_id(tencentEmsCallbackParams.getBulkId());
        entity.setTimestamp(tencentEmsCallbackParams.getTimestamp());
        entity.setReason(tencentEmsCallbackParams.getReason());
        entity.setBounce_type(tencentEmsCallbackParams.getBounceType());
        entity.setUsername(tencentEmsCallbackParams.getUsername());
        entity.setSender(tencentEmsCallbackParams.getFrom());
        entity.setFrom_domain(tencentEmsCallbackParams.getFromDomain());
        entity.setTemplate_id(tencentEmsCallbackParams.getTemplateId());
        entity.setSubject(tencentEmsCallbackParams.getSubject());
        entity.setMessage_id(tencentEmsCallbackParams.getMessageId());
        // 保存记录
        tencentEmsCallbackDao.insert(entity);
    }
}
