package com.storlead.sales.mail.service.impl;

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

import java.util.Collection;
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());
    }
}
