package com.usky.vpp.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

@Configuration
public class VppUnRestTemplateConfig {

    @Bean
    public RestTemplate vppUnRestTemplate(VppUnProperties properties, RestTemplateBuilder builder) {
        int connectMs = properties.getConnectTimeoutMs() != null ? properties.getConnectTimeoutMs() : 10000;
        int readMs = properties.getReadTimeoutMs() != null ? properties.getReadTimeoutMs() : 30000;
        return builder
                .setConnectTimeout(Duration.ofMillis(connectMs))
                .setReadTimeout(Duration.ofMillis(readMs))
                .build();
    }
}
