use chrono::{DateTime, Utc};
use uuid::Uuid;
pub fn generate_href(base_url: &str, resource_type: &str, id: &Uuid) -> String {
format!(
"{}/{}/{}",
base_url.trim_end_matches('/'),
resource_type,
id
)
}
pub fn parse_uuid(s: &str) -> Option<Uuid> {
Uuid::parse_str(s).ok()
}
pub fn format_timestamp(dt: DateTime<Utc>) -> String {
dt.to_rfc3339()
}
pub fn validate_version(version: &str) -> bool {
!version.is_empty()
&& version
.chars()
.all(|c| c.is_alphanumeric() || c == '.' || c == '-')
}
pub fn sanitize_string(s: &str) -> String {
s.trim().to_string()
}
pub fn truncate_string(s: &str, max_len: usize) -> String {
if s.len() <= max_len {
s.to_string()
} else {
format!("{}...", &s[..max_len.saturating_sub(3)])
}
}