package cn.stylefeng.team.generator.sdk.template.config;

import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
import cn.stylefeng.team.generator.api.pojo.template.BizGeneratorTemplateGroup;
import cn.stylefeng.team.generator.api.pojo.template.GeneratorTemplateGroup;
import cn.stylefeng.team.generator.sdk.template.cache.TemplateRedisCache;
import cn.stylefeng.team.generator.sdk.template.cache.biz.BizTemplateRedisCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class TemplateCacheRedisAutoConfiguration {

    @Bean
    public CacheOperatorApi<GeneratorTemplateGroup> generatorTemplateGroupCache(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, GeneratorTemplateGroup> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
        return new TemplateRedisCache(redisTemplate);
    }

    @Bean
    public CacheOperatorApi<BizGeneratorTemplateGroup> bizGeneratorTemplateGroupCache(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, BizGeneratorTemplateGroup> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
        return new BizTemplateRedisCache(redisTemplate);
    }

}
