package com.storlead.mail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.storlead.mail.service.EmailBlacklistRecordService;
import com.storlead.mail.pojo.entity.EmailBlacklistRecordEntity;
import com.storlead.mail.mapper.EmailBlacklistRecordMapper;
import com.storlead.framework.mybatis.service.impl.MyBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 邮箱黑名单 服务实现类
 * </p>
 *
 * @author chenkq
 * @since 2024-10-31
 */
@Service
public class EmailBlacklistRecordServiceImpl extends MyBaseServiceImpl<EmailBlacklistRecordMapper, EmailBlacklistRecordEntity> implements EmailBlacklistRecordService {

    @Override
    public Set<String> getBlackEmaillist(Long userId) {
        LambdaQueryWrapper<EmailBlacklistRecordEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(EmailBlacklistRecordEntity::getOwnerBy,userId);
        queryWrapper.eq(EmailBlacklistRecordEntity::getIsDelete,Integer.valueOf(0));
        List<EmailBlacklistRecordEntity> blacklist = list(queryWrapper);
        if(CollectionUtils.isEmpty(blacklist)) {
            return Collections.emptySet();
        }
        return blacklist.stream().map(EmailBlacklistRecordEntity::getEmailAddress).collect(Collectors.toSet());
    }
}
