package de.avatic.lcc.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;

import java.time.Duration;

/**
 * Konfiguration für Azure Maps Integration
 */
@Configuration
@EnableCaching
public class AzureMapsConfig {

    /**
     * RestTemplate Bean für HTTP-Requests
     */
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder
                .connectTimeout(Duration.ofSeconds(10))
                .readTimeout(Duration.ofSeconds(30))
                .build();
    }

    /**
     * Cache Manager für Token-Caching
     * Tokens werden für 50 Minuten gecacht (Azure Maps Tokens sind 60 Min gültig)
     */
    @Bean
    public CacheManager cacheManager() {
        return new ConcurrentMapCacheManager("azureMapsTokens");
    }
}