use std::fmt;
use crate::model::{FilePayload, InfrastructurePartId, SubjectId};
macro_rules! redacted_debug {
($($name:ident),+ $(,)?) => {
$(
impl fmt::Debug for $name {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(concat!(stringify!($name), "([REDACTED])"))
}
}
)+
};
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct FreeAddress {
pub text: Option<String>,
pub country_code: Option<String>,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct RuianAddress {
pub address_point_code: i64,
pub street: Option<String>,
pub municipality: String,
pub house_number: i64,
pub orientation_number: Option<i64>,
pub orientation_number_letter: Option<String>,
pub postal_code: i64,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum Address {
Free(FreeAddress),
Ruian(RuianAddress),
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct PhysicalPerson {
pub address: Address,
pub name: String,
pub data_box: Option<String>,
pub given_name: Option<String>,
pub surname: Option<String>,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct LegalPerson {
pub address: Address,
pub name: String,
pub data_box: Option<String>,
pub organization_number: Option<String>,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum Person {
Physical(PhysicalPerson),
Legal(LegalPerson),
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct SubjectInfo {
pub id: SubjectId,
pub person: Person,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct Subject {
pub info: SubjectInfo,
pub email: Option<String>,
pub phone: Option<String>,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub struct InfrastructureElementGroup {
pub code: String,
}
impl InfrastructureElementGroup {
pub fn new(code: impl Into<String>) -> Self {
Self { code: code.into() }
}
pub fn as_str(&self) -> &str {
&self.code
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum InfrastructureSubjectRole {
Owner,
Manager,
Operator,
Respondent,
Editor,
Other(String),
}
impl InfrastructureSubjectRole {
pub fn from_raw(raw: impl Into<String>) -> Self {
let raw = raw.into();
match raw.as_str() {
"Vlastnik" => Self::Owner,
"Spravce" => Self::Manager,
"Provozovatel" => Self::Operator,
"Vyjadrovatel" => Self::Respondent,
"Editor" => Self::Editor,
_ => Self::Other(raw),
}
}
pub fn as_str(&self) -> &str {
match self {
Self::Owner => "Vlastnik",
Self::Manager => "Spravce",
Self::Operator => "Provozovatel",
Self::Respondent => "Vyjadrovatel",
Self::Editor => "Editor",
Self::Other(raw) => raw,
}
}
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct InfrastructurePartInfo {
pub id: InfrastructurePartId,
pub name: String,
pub element_group: InfrastructureElementGroup,
pub administrator: SubjectId,
pub owner: Option<Subject>,
pub manager: Option<Subject>,
pub operator: Option<Subject>,
pub respondent: Option<Subject>,
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct InfrastructureRespondentPart {
pub id: InfrastructurePartId,
pub name: String,
pub respondent: SubjectInfo,
pub supporting_file: Option<FilePayload>,
}
redacted_debug!(
FreeAddress,
RuianAddress,
Address,
PhysicalPerson,
LegalPerson,
Person,
SubjectInfo,
Subject,
InfrastructurePartInfo,
InfrastructureRespondentPart,
);