use chrono::{DateTime, Utc};
use url::{ParseError, Url};
use crate::errors::{SuperSTACError, ValidationError};
pub fn get_date_time() -> DateTime<Utc> {
Utc::now()
}
pub fn parse_url(url: &str) -> Result<Url, ParseError> {
Url::parse(url)
}
pub fn validate_identifier(id: &str) -> Result<(), SuperSTACError> {
if id.trim().is_empty() {
return Err(ValidationError::MissingField("id".into()).into());
}
if !id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
return Err(ValidationError::InvalidIdentifier(
"only ASCII letters, digits, hyphen, and underscore are allowed".into(),
)
.into());
}
Ok(())
}