package org.springblade.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.system.entity.VisualSubscribeNotifyConf;
import org.springblade.modules.system.enums.NotifyType;
import org.springblade.modules.system.mapper.VisualSubscribeNotifyConfMapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisualSubscribeNotifyConfService extends ServiceImpl<VisualSubscribeNotifyConfMapper, VisualSubscribeNotifyConf> {

	@Cacheable(cacheNames = "subNotifyConf", key = "#notifyType.name", unless = "#result != null")
	public List<VisualSubscribeNotifyConf> notifyConfList(NotifyType notifyType){
		LambdaQueryWrapper<VisualSubscribeNotifyConf> queryWrapper = Wrappers.<VisualSubscribeNotifyConf>lambdaQuery()
				.eq(VisualSubscribeNotifyConf::getNotifyType, notifyType);
		return list(queryWrapper);
	}
	@Cacheable(cacheNames = "subNotifyConf", key = "#notifyType.name", unless = "#result != null")
	public List<VisualSubscribeNotifyConf> newNotifyConfList(String tenantId,NotifyType notifyType){
		LambdaQueryWrapper<VisualSubscribeNotifyConf> queryWrapper = Wrappers.<VisualSubscribeNotifyConf>lambdaQuery()
				.eq(VisualSubscribeNotifyConf::getTenantId, tenantId)
				.eq(VisualSubscribeNotifyConf::getNotifyType, notifyType);
		return list(queryWrapper);
	}

	@CacheEvict(cacheNames = "subNotifyConf", key = "#notifyType.name")
	public boolean evict(NotifyType notifyType) {
		return true;
	}
}
