package io.synor.dex;

/**
 * DEX client configuration
 */
public class DexConfig {
    private static final String DEFAULT_ENDPOINT = "https://dex.synor.io/v1";
    private static final String DEFAULT_WS_ENDPOINT = "wss://dex.synor.io/v1/ws";
    private static final long DEFAULT_TIMEOUT = 30000;
    private static final int DEFAULT_RETRIES = 3;

    private final String apiKey;
    private final String endpoint;
    private final String wsEndpoint;
    private final long timeout;
    private final int retries;
    private final boolean debug;

    private DexConfig(Builder builder) {
        this.apiKey = builder.apiKey;
        this.endpoint = builder.endpoint != null ? builder.endpoint : DEFAULT_ENDPOINT;
        this.wsEndpoint = builder.wsEndpoint != null ? builder.wsEndpoint : DEFAULT_WS_ENDPOINT;
        this.timeout = builder.timeout > 0 ? builder.timeout : DEFAULT_TIMEOUT;
        this.retries = builder.retries > 0 ? builder.retries : DEFAULT_RETRIES;
        this.debug = builder.debug;
    }

    public String getApiKey() {
        return apiKey;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public String getWsEndpoint() {
        return wsEndpoint;
    }

    public long getTimeout() {
        return timeout;
    }

    public int getRetries() {
        return retries;
    }

    public boolean isDebug() {
        return debug;
    }

    public static Builder builder(String apiKey) {
        return new Builder(apiKey);
    }

    public static class Builder {
        private final String apiKey;
        private String endpoint;
        private String wsEndpoint;
        private long timeout;
        private int retries;
        private boolean debug;

        private Builder(String apiKey) {
            this.apiKey = apiKey;
        }

        public Builder endpoint(String endpoint) {
            this.endpoint = endpoint;
            return this;
        }

        public Builder wsEndpoint(String wsEndpoint) {
            this.wsEndpoint = wsEndpoint;
            return this;
        }

        public Builder timeout(long timeout) {
            this.timeout = timeout;
            return this;
        }

        public Builder retries(int retries) {
            this.retries = retries;
            return this;
        }

        public Builder debug(boolean debug) {
            this.debug = debug;
            return this;
        }

        public DexConfig build() {
            return new DexConfig(this);
        }
    }
}
