package com.smyhub.infogenie.infogeniebackendjava.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;

/**
 * Provides shared RestTemplate instances used by service classes for outbound HTTP calls
 * (auth-center verification, DeepSeek/Kimi AI API, health probe).
 */
@Configuration
public class RestTemplateConfig {

    /** General-purpose client for auth-center and health probes. */
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder
                .connectTimeout(Duration.ofSeconds(10))
                .readTimeout(Duration.ofSeconds(30))
                .build();
    }

    /**
     * Dedicated client for AI API calls — longer read timeout to accommodate
     * slow model inference on the DeepSeek / Kimi endpoints.
     */
    @Bean("aiRestTemplate")
    public RestTemplate aiRestTemplate(RestTemplateBuilder builder) {
        return builder
                .connectTimeout(Duration.ofSeconds(10))
                .readTimeout(Duration.ofSeconds(120))
                .build();
    }
}
