use regex::Regex;
use std::sync::LazyLock;
static UUID_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
.unwrap()
});
static HEX_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[0-9a-fA-F]{16,}$").unwrap());
fn is_id_segment(segment: &str) -> bool {
!segment.is_empty()
&& (segment.bytes().all(|b| b.is_ascii_digit())
|| UUID_RE.is_match(segment)
|| HEX_RE.is_match(segment))
}
pub(crate) fn normalize_endpoint(endpoint: &str) -> String {
let Some(slash) = endpoint.find('/') else {
return endpoint.to_string();
};
let (prefix, path) = endpoint.split_at(slash);
let normalized_path = path
.split('/')
.map(|segment| {
if is_id_segment(segment) {
"{id}"
} else {
segment
}
})
.collect::<Vec<_>>()
.join("/");
format!("{prefix}{normalized_path}")
}