package com.elab.es.client.configuration;

import org.springframework.boot.autoconfigure.elasticsearch.jest.JestProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ES配置属性
 *
 * @author ： liukx
 * @time ： 2020/3/31 - 10:38
 */
@ConfigurationProperties("elab.es") //描述了当前pojo对应的配置文件前缀
public class ElabESProperties {
    /**
     * Comma-separated list of the Elasticsearch instances to use.
     */
    private List<String> uris = new ArrayList<String>(
            Collections.singletonList("http://localhost:9200"));

    /**
     * Login username.
     */
    private String username;

    /**
     * Login password.
     */
    private String password;

    /**
     * Whether to enable connection requests from multiple execution threads.
     */
    private boolean multiThreaded = true;

    /**
     * Connection timeout.
     */
    private Duration connectionTimeout = Duration.ofSeconds(3);

    /**
     * Read timeout.
     */
    private Duration readTimeout = Duration.ofSeconds(3);

    /**
     * Proxy settings.
     */
    private final JestProperties.Proxy proxy = new JestProperties.Proxy();

    public List<String> getUris() {
        return this.uris;
    }

    public void setUris(List<String> uris) {
        this.uris = uris;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isMultiThreaded() {
        return this.multiThreaded;
    }

    public void setMultiThreaded(boolean multiThreaded) {
        this.multiThreaded = multiThreaded;
    }

    public Duration getConnectionTimeout() {
        return this.connectionTimeout;
    }

    public void setConnectionTimeout(Duration connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public Duration getReadTimeout() {
        return this.readTimeout;
    }

    public void setReadTimeout(Duration readTimeout) {
        this.readTimeout = readTimeout;
    }

    public JestProperties.Proxy getProxy() {
        return this.proxy;
    }

    public static class Proxy {

        /**
         * Proxy host the HTTP client should use.
         */
        private String host;

        /**
         * Proxy port the HTTP client should use.
         */
        private Integer port;

        public String getHost() {
            return this.host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public Integer getPort() {
            return this.port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

    }

}
