use anyhow::Result;
use rand::Rng;
pub fn generate_codename(name: &str) -> Result<String> {
let alpha: String = name.chars().filter(|c| c.is_alphabetic()).collect();
if alpha.is_empty() {
anyhow::bail!("Name must contain at least one alphabetic character");
}
let num: String = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(4)
.map(|c| c as char)
.collect();
Ok(format!("{}-{}", alpha, num))
}
pub fn normalize_url(url: &str) -> Result<String> {
let url = url.trim();
if url.is_empty() {
anyhow::bail!("URL cannot be empty");
}
if !url.contains("://") {
Ok(format!("http://{}", url))
} else {
Ok(url.to_string())
}
}