package com.kt.event.content.infra.gateway.client;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Replicate API FeignClient 설정
 *
 * Authorization 헤더 추가 및 로깅 설정
 */
@Slf4j
@Configuration
public class ReplicateApiConfig {

    @Value("${replicate.api.token:}")
    private String apiToken;

    /**
     * Authorization 헤더 추가
     *
     * Replicate API는 "Authorization: Token {api_token}" 형식 요구
     */
    @Bean
    public RequestInterceptor requestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                // Authorization 헤더 추가
                template.header("Authorization", "Token " + apiToken);
                template.header("Content-Type", "application/json");

                log.debug("Replicate API Request: {} {}", template.method(), template.url());
            }
        };
    }
}
