
package com.lideeyunji.tool.framework.yunji.component;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.lideeyunji.tool.framework.yunji.adapter.IlideeYunjiAdapter;
import com.lideeyunji.tool.framework.yunji.component.cache.lideeYunjiCacheAspect;
import com.lideeyunji.tool.framework.yunji.component.crypto.ApiDecryptRequestBodyAdvice;
import com.lideeyunji.tool.framework.yunji.component.crypto.ApiDecryptResponseBodyAdvice;
import com.lideeyunji.tool.framework.yunji.component.defaultval.DefaultValAspect;
import com.lideeyunji.tool.framework.yunji.component.mybatis.MapWrapperFactory;
import com.lideeyunji.tool.framework.yunji.component.properties.lideeYunjiProperties;
import com.lideeyunji.tool.framework.yunji.component.redis.lideeYunjiRedisUtils;
import com.lideeyunji.tool.framework.yunji.component.validate.lideeYunjiValidateAspect;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@EnableConfigurationProperties(lideeYunjiProperties.class)
@Component
public class lideeYunjiAutoConfiguration {

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

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

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

    @Bean
    public lideeYunjiValidateAspect lideeyunJiValidateAspect() {
        return new lideeYunjiValidateAspect();
    }

    //缓存相关
    @Bean
    public lideeYunjiCacheAspect lideeyunJiCacheAspect(lideeYunjiRedisUtils lideeYunjiRedisUtils) {
        return new lideeYunjiCacheAspect(lideeYunjiRedisUtils);
    }

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

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

}
