use crate::proxy::config::ProxyConfig;
use anyhow::Result;
use std::time::Duration;

pub fn build_client(proxy: &ProxyConfig, timeout_secs: u64) -> Result<reqwest::Client> {
    let mut builder = reqwest::Client::builder()
        .timeout(Duration::from_secs(timeout_secs))
        .danger_accept_invalid_certs(false);

    match proxy {
        ProxyConfig::None => {}
        ProxyConfig::Http { url } => {
            builder = builder.proxy(reqwest::Proxy::all(url)?);
        }
        ProxyConfig::Socks5 { url } => {
            builder = builder.proxy(reqwest::Proxy::all(url)?);
        }
    }

    Ok(builder.build()?)
}
