Skip to main content

dpp_domain/ports/registry_sync/
granularity.rs

1//! [`RegistrationGranularity`] — the level a passport is registered at.
2
3use serde::{Deserialize, Serialize};
4
5/// The level a passport is registered at, mirrored in the domain so the port
6/// does not depend on the registry wire crate.
7#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum RegistrationGranularity {
10    /// One registration covering every item sharing a product's specifications.
11    Model,
12    /// One registration covering every item made in one production run.
13    Batch,
14    /// One registration per physical unit.
15    #[default]
16    Item,
17}
18
19impl From<crate::catalog::Granularity> for RegistrationGranularity {
20    /// The registry registers at the level the applicable act fixed.
21    ///
22    /// Direction matters: [`Granularity`](crate::catalog::Granularity) is the
23    /// act's decision under ESPR Art. 9(2)(d), and this type is one consumer of
24    /// it. A conversion the other way would let a registry default answer a
25    /// question only a delegated act can answer, which is why none exists — and
26    /// why this type's `#[default]` of `Item` must never travel back up into the
27    /// catalog.
28    fn from(granularity: crate::catalog::Granularity) -> Self {
29        match granularity {
30            crate::catalog::Granularity::Model => Self::Model,
31            crate::catalog::Granularity::Batch => Self::Batch,
32            crate::catalog::Granularity::Item => Self::Item,
33        }
34    }
35}