dmvs 0.1.1

Async high-level client for selected Czech ČÚZK DMVS SOAP services
Documentation
use std::fmt;

use crate::model::{FilePayload, XmlDateTime};

/// A data type supported by a plain DMVS code-list attribute.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum CodeListDataType {
    /// A numeric value (`Number`).
    Number,
    /// A textual value (`String`).
    String,
    /// A Boolean value (`Boolean`).
    Boolean,
    /// A date value (`Date`).
    Date,
    /// A data type unknown to this crate version, preserved exactly.
    Other(String),
}

impl CodeListDataType {
    pub(crate) fn from_raw(raw: impl Into<String>) -> Self {
        let raw = raw.into();
        match raw.as_str() {
            "Number" => Self::Number,
            "String" => Self::String,
            "Boolean" => Self::Boolean,
            "Date" => Self::Date,
            _ => Self::Other(raw),
        }
    }

    /// Returns the official or untouched unknown data-type value.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Number => "Number",
            Self::String => "String",
            Self::Boolean => "Boolean",
            Self::Date => "Date",
            Self::Other(raw) => raw,
        }
    }
}

/// A reference from one code-list attribute to an attribute of another code list.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListAttributeReference {
    /// Identifier of the referenced code list.
    pub code_list_id: String,
    /// Identifier of the referenced attribute.
    pub attribute_id: String,
}

/// The value representation of a code-list attribute.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum CodeListAttributeKind {
    /// A directly stored value with the specified data type.
    Plain(CodeListDataType),
    /// A value referenced through another code-list attribute.
    Reference(CodeListAttributeReference),
}

/// Metadata for one attribute of a DMVS code list.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListAttribute {
    /// Code-list-local attribute identifier.
    pub id: String,
    /// Human-readable attribute name.
    pub name: String,
    /// Plain data type or reference definition.
    pub kind: CodeListAttributeKind,
}

/// Version metadata for a DMVS code list.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListVersionInfo {
    /// Version identifier, retained as a string.
    pub version: String,
    /// Start of validity.
    pub valid_from: XmlDateTime,
    /// Optional end of validity.
    pub valid_to: Option<XmlDateTime>,
}

/// Code-list discovery metadata returned by R24a `vylistujCiselniky`.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListInfo {
    /// Opaque DMVS code-list identifier.
    pub id: String,
    /// Human-readable code-list name.
    pub name: String,
    /// Attribute definitions in server order.
    pub attributes: Vec<CodeListAttribute>,
    /// Metadata for the latest published version.
    pub latest_version: CodeListVersionInfo,
}

/// One attribute value in a code-list item.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListItemAttribute {
    /// Identifier of the attribute defined by the code list.
    pub id: String,
    /// Raw attribute value, without interpreting its declared data type.
    pub value: String,
}

/// One item in a selected code-list version.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeListItem {
    /// Attribute values in server order.
    pub attributes: Vec<CodeListItemAttribute>,
    /// Whether the item has been invalidated.
    pub invalidated: bool,
}

/// A selected code-list version returned by R24a `ctiCiselnik`.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CodeList {
    /// Opaque DMVS code-list identifier.
    pub id: String,
    /// Human-readable code-list name.
    pub name: String,
    /// Attribute definitions in server order.
    pub attributes: Vec<CodeListAttribute>,
    /// Metadata for the returned version.
    pub version: CodeListVersionInfo,
    /// Items in server order.
    pub items: Vec<CodeListItem>,
}

/// One complete JVF version returned by R24a `ctiVerziJvf`.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct JvfVersion {
    /// Version identifier, such as `1.4.3`.
    pub version: String,
    /// Start of validity.
    pub valid_from: XmlDateTime,
    /// Optional end of validity.
    pub valid_to: Option<XmlDateTime>,
    /// Official version description.
    pub description: String,
    /// Original JVF content and its file metadata.
    pub content: FilePayload,
}

/// An IS DMVS authentication certificate returned by R24a
/// `vylistujCertifikatyIsDmvs`.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct IsDmvsCertificate {
    /// Date and time when IS DMVS started using the certificate.
    pub usage_started_at: XmlDateTime,
    /// Start of certificate validity.
    pub valid_from: XmlDateTime,
    /// End of certificate validity.
    pub valid_to: XmlDateTime,
    /// PEM-encoded certificate exactly as returned by the service.
    pub certificate_pem: String,
}

impl fmt::Debug for IsDmvsCertificate {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("IsDmvsCertificate")
            .field("usage_started_at", &self.usage_started_at)
            .field("valid_from", &self.valid_from)
            .field("valid_to", &self.valid_to)
            .field("certificate_pem", &"[REDACTED]")
            .finish()
    }
}