package com.inspect.gateway.config;

import com.inspect.gateway.handler.ValidateCodeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

@Configuration
public class RouterFunctionConfiguration {
    private final ValidateCodeHandler validateCodeHandler;

    public RouterFunctionConfiguration(ValidateCodeHandler validateCodeHandler) {
        this.validateCodeHandler = validateCodeHandler;
    }

    @Bean
    public RouterFunction routerFunction() {
        return RouterFunctions.route(RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), this.validateCodeHandler);
    }
}
