use crate::error::ValidationError;
use crate::jurisdiction::Jurisdiction;
use crate::validation::validate_name;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ProjectSpec {
name: String,
jurisdiction: Jurisdiction,
}
impl ProjectSpec {
#[must_use]
pub fn new(name: impl Into<String>, jurisdiction: Jurisdiction) -> Self {
Self {
name: name.into(),
jurisdiction,
}
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub const fn jurisdiction(&self) -> Jurisdiction {
self.jurisdiction
}
pub fn validate(&self) -> Result<(), ValidationError> {
validate_name("name", &self.name)
}
}
#[cfg(test)]
#[allow(clippy::expect_used)]
mod tests {
use super::*;
#[test]
fn valid_project_spec_passes_validation() {
let spec = ProjectSpec::new("my-project", Jurisdiction::DE);
assert!(spec.validate().is_ok());
}
#[test]
fn project_rejects_invalid_name() {
let spec = ProjectSpec::new("BAD", Jurisdiction::DE);
assert!(spec.validate().is_err());
}
#[test]
fn project_accessors_return_correct_values() {
let spec = ProjectSpec::new("my-project", Jurisdiction::FR);
assert_eq!(spec.name(), "my-project");
assert_eq!(spec.jurisdiction(), Jurisdiction::FR);
let cloned = spec.clone();
assert_eq!(spec, cloned);
}
}