package gaf3.core.cloud

import gaf3.core.cloud.web.GafControllerAdvice
import gaf3.core.cloud.web.GafSpaConfigure
import gaf3.core.cloud.web.reactive.GafSpaWebFilter
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import gaf3.core.cloud.web.reactive.GafControllerAdvice as GafReactiveControllerAdvice

@Configuration
@EnableConfigurationProperties(GafSpaConfigure::class)
class GafCloudConfiguration {

    @Bean
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
    fun gafControllerAdvice(): GafControllerAdvice {
        return GafControllerAdvice()
    }

    @Bean
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    fun gafReactiveControllerAdvice(): GafReactiveControllerAdvice {
        return GafReactiveControllerAdvice()
    }

    @Bean
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    fun gafReactiveSPAWebFilter(config: GafSpaConfigure): GafSpaWebFilter {
        return GafSpaWebFilter(config)
    }
}

