use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::collections::HashMap;
use std::str::FromStr;

pub fn build_headers(headers: &HashMap<String, String>) -> HeaderMap {
    let mut map: HeaderMap = HeaderMap::new();
    for (k, v) in headers {
        match (HeaderName::from_str(k), HeaderValue::from_str(v)) {
            (Ok(name), Ok(value)) => {
                map.insert(name, value);
            }
            (Err(e), _) => {
                tracing::warn!("Skipping invalid header name '{}': {}", k, e);
            }
            (_, Err(e)) => {
                tracing::warn!("Skipping header '{}' with invalid value: {}", k, e);
            }
        }
    }
    map
}
