package com.steerinfo.meterwork.rtdb;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * Tarantool / icore-rtdb 连接池配置。
 */
@ConfigurationProperties(prefix = "rtdb")
public class RtdbPoolProperties {

    private String host = "172.22.42.3";
    private int port = 2101;
    private String username = "guest";
    private String password = "";
    private final Pool pool = new Pool();
    private final Monitor monitor = new Monitor();

    public String getHost() {
        return host;
    }

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

    public int getPort() {
        return port;
    }

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

    public String getUsername() {
        return username;
    }

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

    public String getPassword() {
        return password;
    }

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

    public Pool getPool() {
        return pool;
    }

    public Monitor getMonitor() {
        return monitor;
    }

    public String address() {
        return host + ":" + port;
    }

    public static class Pool {
        private int size = 8;
        private long borrowTimeoutMs = 3000L;

        public int getSize() {
            return size;
        }

        public void setSize(int size) {
            this.size = size;
        }

        public long getBorrowTimeoutMs() {
            return borrowTimeoutMs;
        }

        public void setBorrowTimeoutMs(long borrowTimeoutMs) {
            this.borrowTimeoutMs = borrowTimeoutMs;
        }
    }

    public static class Monitor {
        /** 是否启用 Monitor 写 Tarantool */
        @Value("${rtdb.monitor.enabled:true}")
        private boolean enabled;
        /** Tarantool 失败时是否回退 Oracle */
        @Value("${rtdb.monitor.fallback-oracle:false}")
        private boolean fallbackOracle;
        /** 启动时从 Oracle 全量灌入 Tarantool */
        @Value("${rtdb.monitor.bootstrap-enabled:false}")
        private boolean bootstrapEnabled;

        @Value("${meter.monitor.sync.enabled:true}")
        private boolean syncEnabled;

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public boolean isFallbackOracle() {
            return fallbackOracle;
        }

        public void setFallbackOracle(boolean fallbackOracle) {
            this.fallbackOracle = fallbackOracle;
        }

        public boolean isBootstrapEnabled() {
            return bootstrapEnabled;
        }

        public void setBootstrapEnabled(boolean bootstrapEnabled) {
            this.bootstrapEnabled = bootstrapEnabled;
        }

        public boolean isSyncEnabled() {
            return syncEnabled;
        }

        public void setSyncEnabled(boolean syncEnabled) {
            this.syncEnabled = syncEnabled;
        }
    }
}
