package kz.konturai.parser.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;

import java.time.Duration;

@Configuration
public class FacebookLeadWebClientConfig {

    @Bean
    @Qualifier("facebookLeadWebClient")
    public WebClient facebookLeadWebClient(WebClient.Builder webClientBuilder, FacebookLeadProperties properties) {
        HttpClient httpClient = HttpClient.create()
                .responseTimeout(Duration.ofMillis(properties.getTimeoutMs()));

        return webClientBuilder
                .baseUrl("https://graph.facebook.com/" + properties.getGraphApiVersion())
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .build();
    }
}
