
package com.jeelowcode.framework.utils.component;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
import com.jeelowcode.framework.utils.component.cache.JeelowCodeCacheAspect;
import com.jeelowcode.framework.utils.component.crypto.ApiDecryptRequestBodyAdvice;
import com.jeelowcode.framework.utils.component.crypto.ApiDecryptResponseBodyAdvice;
import com.jeelowcode.framework.utils.component.defaultval.DefaultValAspect;
import com.jeelowcode.framework.utils.component.mybatis.MapWrapperFactory;
import com.jeelowcode.framework.utils.component.properties.JeeLowCodeProperties;
import com.jeelowcode.framework.utils.component.redis.JeeLowCodeRedisUtils;
import com.jeelowcode.framework.utils.component.validate.JeelowCodeValidateAspect;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@EnableConfigurationProperties(JeeLowCodeProperties.class)
@Component
public class JeeLowCodeAutoConfiguration {

    // ========== AOP ==========

    @Bean
    public ApiDecryptRequestBodyAdvice apiDecryptRequestBodyAdvice() {
        return new ApiDecryptRequestBodyAdvice();
    }

    @Bean
    public ApiDecryptResponseBodyAdvice apiDecryptResponseBodyAdvice() {
        return new ApiDecryptResponseBodyAdvice();
    }

    @Bean
    public JeelowCodeValidateAspect jeelowCodeValidateAspect() {
        return new JeelowCodeValidateAspect();
    }

    //缓存相关
    @Bean
    public JeelowCodeCacheAspect jeelowCodeCacheAspect(JeeLowCodeRedisUtils jeeLowCodeRedisUtils) {
        return new JeelowCodeCacheAspect(jeeLowCodeRedisUtils);
    }

    //默认值处理相关
    @Bean
    public DefaultValAspect defaultValAspect(IJeeLowCodeAdapter proxyAdapter) {
        return new DefaultValAspect(proxyAdapter);
    }

    //mybatis 返回值大写转小写
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> configuration.setObjectWrapperFactory(new MapWrapperFactory());
    }

}
