use serde::{Deserialize, Serialize};
use super::{validate_ror_id, ValidationError};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Affiliation {
pub name: String,
pub ror_id: Option<String>,
pub country: Option<String>,
}
impl Affiliation {
pub fn new(name: impl Into<String>) -> Self {
Self { name: name.into(), ror_id: None, country: None }
}
pub fn with_ror_id(mut self, ror_id: impl Into<String>) -> Result<Self, ValidationError> {
let ror = ror_id.into();
if !validate_ror_id(&ror) {
return Err(ValidationError::InvalidRorId(ror));
}
self.ror_id = Some(ror);
Ok(self)
}
pub fn with_country(mut self, country: impl Into<String>) -> Self {
self.country = Some(country.into());
self
}
}