package com.storlead.mail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.storlead.framework.common.constant.CommonConstant;
import com.storlead.mail.service.SmtpPopSettingsService;
import com.storlead.mail.pojo.entity.SmtpPopSettingsEntity;
import com.storlead.mail.mapper.SmtpPopSettingsMapper;
import com.storlead.framework.mybatis.service.impl.MyBaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 邮箱smtp_setting 服务实现类
 * </p>
 *
 * @author chenkq
 * @since 2024-05-28
 */
@Service
public class SmtpPopSettingsServiceImpl extends MyBaseServiceImpl<SmtpPopSettingsMapper, SmtpPopSettingsEntity> implements SmtpPopSettingsService {

    @Override
    public SmtpPopSettingsEntity getDefaultSmtpPop(Long userId) {
        LambdaQueryWrapper<SmtpPopSettingsEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(SmtpPopSettingsEntity::getOwnerBy,userId);
        wrapper.eq(SmtpPopSettingsEntity::getIsDelete,CommonConstant.DEL_FLAG_0);
        wrapper.eq(SmtpPopSettingsEntity::getUseDefault,Integer.valueOf(1));
        wrapper.last(" limit 1");
        SmtpPopSettingsEntity entity = this.getOne(wrapper);
        return entity;
    }

    @Override
    public SmtpPopSettingsEntity getSystemSmtpPop(Long popId) {
        SmtpPopSettingsEntity entity = this.getById(popId);
        return entity;
    }

    @Override
    public List<SmtpPopSettingsEntity> getDefaultSmtpPopls(Set userIds){
        LambdaQueryWrapper<SmtpPopSettingsEntity> wrapper = new LambdaQueryWrapper();
        wrapper.in(SmtpPopSettingsEntity::getOwnerBy,userIds);
        wrapper.eq(SmtpPopSettingsEntity::getUseDefault,Integer.valueOf(1));
        List<SmtpPopSettingsEntity> entityls = this.list(wrapper);
        return entityls;
    }
    @Override
    public List<SmtpPopSettingsEntity> getEmailAccount(Long userId) {
        LambdaQueryWrapper<SmtpPopSettingsEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(SmtpPopSettingsEntity::getOwnerBy,userId);
        wrapper.eq(SmtpPopSettingsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
        return this.list(wrapper);
    }

    @Override
    public SmtpPopSettingsEntity getEmailByAccountPopId(Long userId, Long popId) {
        LambdaQueryWrapper<SmtpPopSettingsEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(SmtpPopSettingsEntity::getOwnerBy,userId);
        wrapper.eq(SmtpPopSettingsEntity::getId,popId);
        wrapper.eq(SmtpPopSettingsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
        wrapper.last("limit 1");
        return this.getOne(wrapper);
    }
}
