Skip to main content

dmvs/model/
codelists.rs

1use std::fmt;
2
3use crate::model::{FilePayload, XmlDateTime};
4
5/// A data type supported by a plain DMVS code-list attribute.
6#[derive(Clone, Debug, Eq, Hash, PartialEq)]
7#[non_exhaustive]
8pub enum CodeListDataType {
9    /// A numeric value (`Number`).
10    Number,
11    /// A textual value (`String`).
12    String,
13    /// A Boolean value (`Boolean`).
14    Boolean,
15    /// A date value (`Date`).
16    Date,
17    /// A data type unknown to this crate version, preserved exactly.
18    Other(String),
19}
20
21impl CodeListDataType {
22    pub(crate) fn from_raw(raw: impl Into<String>) -> Self {
23        let raw = raw.into();
24        match raw.as_str() {
25            "Number" => Self::Number,
26            "String" => Self::String,
27            "Boolean" => Self::Boolean,
28            "Date" => Self::Date,
29            _ => Self::Other(raw),
30        }
31    }
32
33    /// Returns the official or untouched unknown data-type value.
34    pub fn as_str(&self) -> &str {
35        match self {
36            Self::Number => "Number",
37            Self::String => "String",
38            Self::Boolean => "Boolean",
39            Self::Date => "Date",
40            Self::Other(raw) => raw,
41        }
42    }
43}
44
45/// A reference from one code-list attribute to an attribute of another code list.
46#[derive(Clone, Debug, Eq, PartialEq)]
47#[non_exhaustive]
48pub struct CodeListAttributeReference {
49    /// Identifier of the referenced code list.
50    pub code_list_id: String,
51    /// Identifier of the referenced attribute.
52    pub attribute_id: String,
53}
54
55/// The value representation of a code-list attribute.
56#[derive(Clone, Debug, Eq, PartialEq)]
57#[non_exhaustive]
58pub enum CodeListAttributeKind {
59    /// A directly stored value with the specified data type.
60    Plain(CodeListDataType),
61    /// A value referenced through another code-list attribute.
62    Reference(CodeListAttributeReference),
63}
64
65/// Metadata for one attribute of a DMVS code list.
66#[derive(Clone, Debug, Eq, PartialEq)]
67#[non_exhaustive]
68pub struct CodeListAttribute {
69    /// Code-list-local attribute identifier.
70    pub id: String,
71    /// Human-readable attribute name.
72    pub name: String,
73    /// Plain data type or reference definition.
74    pub kind: CodeListAttributeKind,
75}
76
77/// Version metadata for a DMVS code list.
78#[derive(Clone, Debug, Eq, PartialEq)]
79#[non_exhaustive]
80pub struct CodeListVersionInfo {
81    /// Version identifier, retained as a string.
82    pub version: String,
83    /// Start of validity.
84    pub valid_from: XmlDateTime,
85    /// Optional end of validity.
86    pub valid_to: Option<XmlDateTime>,
87}
88
89/// Code-list discovery metadata returned by R24a `vylistujCiselniky`.
90#[derive(Clone, Debug, Eq, PartialEq)]
91#[non_exhaustive]
92pub struct CodeListInfo {
93    /// Opaque DMVS code-list identifier.
94    pub id: String,
95    /// Human-readable code-list name.
96    pub name: String,
97    /// Attribute definitions in server order.
98    pub attributes: Vec<CodeListAttribute>,
99    /// Metadata for the latest published version.
100    pub latest_version: CodeListVersionInfo,
101}
102
103/// One attribute value in a code-list item.
104#[derive(Clone, Debug, Eq, PartialEq)]
105#[non_exhaustive]
106pub struct CodeListItemAttribute {
107    /// Identifier of the attribute defined by the code list.
108    pub id: String,
109    /// Raw attribute value, without interpreting its declared data type.
110    pub value: String,
111}
112
113/// One item in a selected code-list version.
114#[derive(Clone, Debug, Eq, PartialEq)]
115#[non_exhaustive]
116pub struct CodeListItem {
117    /// Attribute values in server order.
118    pub attributes: Vec<CodeListItemAttribute>,
119    /// Whether the item has been invalidated.
120    pub invalidated: bool,
121}
122
123/// A selected code-list version returned by R24a `ctiCiselnik`.
124#[derive(Clone, Debug, Eq, PartialEq)]
125#[non_exhaustive]
126pub struct CodeList {
127    /// Opaque DMVS code-list identifier.
128    pub id: String,
129    /// Human-readable code-list name.
130    pub name: String,
131    /// Attribute definitions in server order.
132    pub attributes: Vec<CodeListAttribute>,
133    /// Metadata for the returned version.
134    pub version: CodeListVersionInfo,
135    /// Items in server order.
136    pub items: Vec<CodeListItem>,
137}
138
139/// One complete JVF version returned by R24a `ctiVerziJvf`.
140#[derive(Clone, Debug, Eq, PartialEq)]
141#[non_exhaustive]
142pub struct JvfVersion {
143    /// Version identifier, such as `1.4.3`.
144    pub version: String,
145    /// Start of validity.
146    pub valid_from: XmlDateTime,
147    /// Optional end of validity.
148    pub valid_to: Option<XmlDateTime>,
149    /// Official version description.
150    pub description: String,
151    /// Original JVF content and its file metadata.
152    pub content: FilePayload,
153}
154
155/// An IS DMVS authentication certificate returned by R24a
156/// `vylistujCertifikatyIsDmvs`.
157#[derive(Clone, Eq, PartialEq)]
158#[non_exhaustive]
159pub struct IsDmvsCertificate {
160    /// Date and time when IS DMVS started using the certificate.
161    pub usage_started_at: XmlDateTime,
162    /// Start of certificate validity.
163    pub valid_from: XmlDateTime,
164    /// End of certificate validity.
165    pub valid_to: XmlDateTime,
166    /// PEM-encoded certificate exactly as returned by the service.
167    pub certificate_pem: String,
168}
169
170impl fmt::Debug for IsDmvsCertificate {
171    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
172        formatter
173            .debug_struct("IsDmvsCertificate")
174            .field("usage_started_at", &self.usage_started_at)
175            .field("valid_from", &self.valid_from)
176            .field("valid_to", &self.valid_to)
177            .field("certificate_pem", &"[REDACTED]")
178            .finish()
179    }
180}