Skip to main content

entrenar/research/artifact/
affiliation.rs

1//! Institutional affiliation with optional ROR identifier.
2
3use serde::{Deserialize, Serialize};
4
5use super::{validate_ror_id, ValidationError};
6
7/// Institutional affiliation with optional ROR identifier
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct Affiliation {
10    /// Institution name
11    pub name: String,
12    /// Research Organization Registry ID (optional)
13    pub ror_id: Option<String>,
14    /// Country code (ISO 3166-1 alpha-2)
15    pub country: Option<String>,
16}
17
18impl Affiliation {
19    /// Create a new affiliation
20    pub fn new(name: impl Into<String>) -> Self {
21        Self { name: name.into(), ror_id: None, country: None }
22    }
23
24    /// Set the ROR ID (validates format)
25    pub fn with_ror_id(mut self, ror_id: impl Into<String>) -> Result<Self, ValidationError> {
26        let ror = ror_id.into();
27        if !validate_ror_id(&ror) {
28            return Err(ValidationError::InvalidRorId(ror));
29        }
30        self.ror_id = Some(ror);
31        Ok(self)
32    }
33
34    /// Set the country code
35    pub fn with_country(mut self, country: impl Into<String>) -> Self {
36        self.country = Some(country.into());
37        self
38    }
39}