use crate::error::AybError;
use std::collections::HashSet;
const RESERVED_USERNAMES_RAW: &str = include_str!("reserved-usernames.txt");
fn load_banned_usernames() -> HashSet<String> {
RESERVED_USERNAMES_RAW
.lines()
.map(|line| line.trim())
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.map(|line| line.to_lowercase())
.collect()
}
pub fn is_username_banned(username: &str) -> bool {
static BANNED_USERNAMES: std::sync::OnceLock<HashSet<String>> = std::sync::OnceLock::new();
let banned_set = BANNED_USERNAMES.get_or_init(load_banned_usernames);
banned_set.contains(&username.to_lowercase())
}
pub fn validate_username(username: &str) -> Result<(), AybError> {
if is_username_banned(username) {
return Err(AybError::RegistrationError {
message: format!("Username '{username}' is reserved and cannot be used"),
});
}
Ok(())
}