use core::fmt;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum RemoteEntity {
Project,
Person,
Organization,
Repository,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RemoteOrganizationRole {
#[default]
Any,
SiteOwner,
Research,
Sponsor,
Contributor,
Developer,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Organization {
pub name: String,
pub aliases: Vec<String>,
pub roles: Vec<String>,
pub project_ids: Vec<u64>,
pub project_titles: Vec<String>,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Person {
pub name: String,
pub orcid: Option<String>,
pub email: Option<String>,
pub affiliations: Vec<String>,
pub roles: Vec<String>,
pub project_ids: Vec<u64>,
pub project_titles: Vec<String>,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProjectOrganization {
#[serde(default)]
pub organization_name: String,
#[serde(default, rename = "DOE")]
pub doe: bool,
#[serde(default)]
pub primary_award: Option<String>,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProjectPerson {
#[serde(default)]
pub email: String,
#[serde(default)]
pub orcid: String,
#[serde(default)]
pub first_name: String,
#[serde(default)]
pub last_name: String,
#[serde(default)]
pub middle_name: String,
#[serde(default)]
pub contributor_type: Option<String>,
#[serde(default)]
pub affiliations: Vec<String>,
}
impl ProjectPerson {
pub fn name(&self) -> String {
[&self.first_name, &self.middle_name, &self.last_name]
.into_iter()
.filter(|part| !part.trim().is_empty())
.map(|part| part.trim())
.collect::<Vec<_>>()
.join(" ")
}
}
impl fmt::Display for RemoteEntity {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
| Self::Project => "project",
| Self::Person => "person",
| Self::Organization => "organization",
| Self::Repository => "repository",
})
}
}
impl fmt::Display for RemoteOrganizationRole {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
| Self::Any => "any",
| Self::SiteOwner => "site-owner",
| Self::Research => "research",
| Self::Sponsor => "sponsor",
| Self::Contributor => "contributor",
| Self::Developer => "developer",
})
}
}