package gc.mda.signal_batch.global.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.reactive.function.client.WebClient;

/**
 * S&P Global AIS API WebClient 설정
 *
 * API: POST /AisSvc.svc/AIS/GetTargetsEnhanced
 * 인증: Basic Authentication
 * 버퍼: 50MB (AIS GetTargets 응답 ~20MB+)
 */
@Slf4j
@Configuration
@Profile("!query")
public class AisApiWebClientConfig {

    @Value("${app.ais-api.url}")
    private String aisApiUrl;

    @Value("${app.ais-api.username}")
    private String aisApiUsername;

    @Value("${app.ais-api.password}")
    private String aisApiPassword;

    @Bean(name = "aisApiWebClient")
    public WebClient aisApiWebClient() {
        log.info("AIS API WebClient 생성 - Base URL: {}", aisApiUrl);

        return WebClient.builder()
                .baseUrl(aisApiUrl)
                .defaultHeaders(headers -> headers.setBasicAuth(aisApiUsername, aisApiPassword))
                .codecs(configurer -> configurer
                        .defaultCodecs()
                        .maxInMemorySize(50 * 1024 * 1024))
                .build();
    }
}
