package com.spring.infra.feign.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.boot.context.properties.bind.DefaultValue;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@ConstructorBinding
@ConfigurationProperties(prefix = "feign")
@RequiredArgsConstructor
public class FeignClientProperties {

    private final Map<String, ClientConfig> clients;

    @Getter
    public static class ClientConfig {
        private final String url;
        private final int connectTimeout;
        private final int readTimeout;
        private final String proxyHost;
        private final int proxyPort;
        private final boolean useProxy;
        private final Map<String, String> headers;

        public ClientConfig(
            String url,
            @DefaultValue("5000") int connectTimeout,
            @DefaultValue("5000") int readTimeout,
            @DefaultValue("") String proxyHost,
            @DefaultValue("0") int proxyPort,
            @DefaultValue("false") boolean useProxy,
            Map<String, String> headers
        ) {
            this.url = url;
            this.connectTimeout = connectTimeout;
            this.readTimeout = readTimeout;
            this.proxyHost = proxyHost;
            this.proxyPort = proxyPort;
            this.useProxy = useProxy;
            this.headers = headers != null ? headers : new HashMap<>();
        }
    }

}
