use once_cell::sync::Lazy;
use std::time::Duration;

use crate::config_validation::runtime_env_settings;

const DEFAULT_DEADPOOL_CHECKOUT_TIMEOUT_MS: u64 = 800;

static DEADPOOL_CHECKOUT_TIMEOUT: Lazy<Duration> = Lazy::new(|| {
    let timeout_ms: u64 = runtime_env_settings()
        .deadpool_checkout_timeout_ms
        .max(DEFAULT_DEADPOOL_CHECKOUT_TIMEOUT_MS);
    Duration::from_millis(timeout_ms)
});

pub fn deadpool_checkout_timeout() -> Duration {
    *DEADPOOL_CHECKOUT_TIMEOUT
}
