package com.sikey.wa04.business.infrastructure.configuration;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@Slf4j
public class RestRoutesLoggingConfig {
    private final RequestMappingHandlerMapping handlerMapping;

    public RestRoutesLoggingConfig(RequestMappingHandlerMapping requestMappingHandlerMapping) {
        this.handlerMapping = requestMappingHandlerMapping;
    }

    @Bean
    public CommandLineRunner printRoutes() {
        return printRoutes -> handlerMapping.getHandlerMethods().forEach((key, value) ->
                log.info("{} : {}", key, value.getMethod()));
    }
}
