dmvs 0.1.1

Async high-level client for selected Czech ČÚZK DMVS SOAP services
Documentation
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])"))
                }
            }
        )+
    };
}

/// A free-form postal address.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct FreeAddress {
    /// Free-form address text (`AdresaTextem`).
    pub text: Option<String>,
    /// Country code (`KodZeme`), retained without interpreting the code list.
    pub country_code: Option<String>,
}

/// A structured RÚIAN postal address.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct RuianAddress {
    /// RÚIAN address-point code (`AdresniMisto/Kod`).
    pub address_point_code: i64,
    /// Optional street name (`Ulice`).
    pub street: Option<String>,
    /// Municipality name (`Obec`).
    pub municipality: String,
    /// House number (`CisloDomovni`).
    pub house_number: i64,
    /// Optional orientation number (`CisloOrientacni`).
    pub orientation_number: Option<i64>,
    /// Optional letter suffix of the orientation number (`CisloOrientacniPismeno`).
    pub orientation_number_letter: Option<String>,
    /// Numeric postal code (`Psc`), represented exactly as the XSD `long` value.
    pub postal_code: i64,
}

/// The address choice used by a registered person or organization.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum Address {
    /// A free-form address (`AdresaVolna`).
    Free(FreeAddress),
    /// A structured RÚIAN address (`AdresaRuian`).
    Ruian(RuianAddress),
}

/// A physical person in the IS DMVS subject registry.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct PhysicalPerson {
    /// Postal address.
    pub address: Address,
    /// Display name (`Nazev`), which may be empty under the XSD.
    pub name: String,
    /// Optional data-box identifier (`DatovaSchranka`).
    pub data_box: Option<String>,
    /// Optional given name (`Jmeno`).
    pub given_name: Option<String>,
    /// Optional surname (`Prijmeni`).
    pub surname: Option<String>,
}

/// A legal person or organization in the IS DMVS subject registry.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct LegalPerson {
    /// Postal address.
    pub address: Address,
    /// Organization name (`Nazev`), which may be empty under the XSD.
    pub name: String,
    /// Optional data-box identifier (`DatovaSchranka`).
    pub data_box: Option<String>,
    /// Optional organization identification number (IČO; XML `Ico`), retained as a string.
    pub organization_number: Option<String>,
}

/// The physical/legal-person choice in an IS DMVS subject.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum Person {
    /// A physical person (`FyzickaOsoba`).
    Physical(PhysicalPerson),
    /// A legal person (`PravnickaOsoba`).
    Legal(LegalPerson),
}

/// Subject identity and person information without direct contact details.
///
/// This is the `SubjektEvidenceDtiInfo` shape returned by R18a and R18b.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct SubjectInfo {
    /// Opaque IS DMVS subject identifier.
    pub id: SubjectId,
    /// Physical or legal person details.
    pub person: Person,
}

/// A full registry subject, including optional direct contact details.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct Subject {
    /// Subject identity and person information.
    pub info: SubjectInfo,
    /// Optional e-mail address (`Email`).
    pub email: Option<String>,
    /// Optional telephone number (`Telefon`).
    pub phone: Option<String>,
}

/// An infrastructure element-group reference.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub struct InfrastructureElementGroup {
    /// Code-list value (`Kod`), retained without restricting future codes.
    pub code: String,
}

impl InfrastructureElementGroup {
    /// Creates a group reference without restricting current or future codes.
    pub fn new(code: impl Into<String>) -> Self {
        Self { code: code.into() }
    }

    /// Returns the untouched code-list value.
    pub fn as_str(&self) -> &str {
        &self.code
    }
}

/// A subject role accepted by the approved R18b searches.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum InfrastructureSubjectRole {
    /// Infrastructure owner (`Vlastnik`).
    Owner,
    /// Infrastructure manager (`Spravce`).
    Manager,
    /// Infrastructure operator (`Provozovatel`).
    Operator,
    /// Respondent (`Vyjadrovatel`).
    Respondent,
    /// Editor (`Editor`), valid for identification search but not part-based search.
    Editor,
    /// A future or otherwise unknown role, preserved exactly.
    Other(String),
}

impl InfrastructureSubjectRole {
    /// Creates a role while retaining unknown values exactly.
    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),
        }
    }

    /// Returns the official or untouched unknown protocol value.
    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,
        }
    }
}

/// Shared infrastructure-part identity, element group, and responsible roles used by R49.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct InfrastructurePartInfo {
    /// Opaque infrastructure-part identifier.
    pub id: InfrastructurePartId,
    /// Part name (`Nazev`).
    pub name: String,
    /// Infrastructure element group.
    pub element_group: InfrastructureElementGroup,
    /// Administrator subject identifier.
    pub administrator: SubjectId,
    /// Optional full owner contact (`Vlastnik`).
    pub owner: Option<Subject>,
    /// Optional full manager contact (`Spravce`).
    pub manager: Option<Subject>,
    /// Optional full operator contact (`Provozovatel`).
    pub operator: Option<Subject>,
    /// Optional full respondent contact (`Vyjadrovatel`).
    pub respondent: Option<Subject>,
}

/// One infrastructure part and its respondent returned by R18a `ctiVyjadrovatele`.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct InfrastructureRespondentPart {
    /// Opaque infrastructure-part identifier.
    pub id: InfrastructurePartId,
    /// Part name (`Nazev`).
    pub name: String,
    /// Respondent identity and person information, without direct contacts.
    pub respondent: SubjectInfo,
    /// Optional respondent-supporting text file (`PodkladyProVyjadrovatele`).
    pub supporting_file: Option<FilePayload>,
}

redacted_debug!(
    FreeAddress,
    RuianAddress,
    Address,
    PhysicalPerson,
    LegalPerson,
    Person,
    SubjectInfo,
    Subject,
    InfrastructurePartInfo,
    InfrastructureRespondentPart,
);