package com.yifu.cloud.plus.v1.yifu.gateway.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yifu.cloud.plus.v1.yifu.gateway.filter.PasswordDecoderFilter;
import com.yifu.cloud.plus.v1.yifu.gateway.filter.YifuRequestGlobalFilter;
import com.yifu.cloud.plus.v1.yifu.gateway.filter.YifuSpringDocGlobalFilter;
import com.yifu.cloud.plus.v1.yifu.gateway.filter.ValidateCodeGatewayFilter;
import com.yifu.cloud.plus.v1.yifu.gateway.handler.GlobalExceptionHandler;
import com.yifu.cloud.plus.v1.yifu.gateway.handler.ImageCodeHandler;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * 网关配置
 *
 * @author L.cm
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(GatewayConfigProperties.class)
public class GatewayConfiguration {

	@Bean
	public PasswordDecoderFilter passwordDecoderFilter(GatewayConfigProperties configProperties) {
		return new PasswordDecoderFilter(configProperties);
	}

	@Bean
	public YifuRequestGlobalFilter yifuRequestGlobalFilter() {
		return new YifuRequestGlobalFilter();
	}

	@Bean
	public YifuSpringDocGlobalFilter yifuSwaggerGlobalFilter() {
		return new YifuSpringDocGlobalFilter();
	}

	@Bean
	public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties,
			ObjectMapper objectMapper, RedisTemplate redisTemplate) {
		return new ValidateCodeGatewayFilter(configProperties, objectMapper, redisTemplate);
	}

	@Bean
	public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) {
		return new GlobalExceptionHandler(objectMapper);
	}

	@Bean
	public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) {
		return new ImageCodeHandler(redisTemplate);
	}

}
