use core::fmt;
use openehr_mapping_core::header::archetype::ArchetypeId;
use openehr_mapping_core::header::metadata::MappingName;
use openehr_mapping_core::header::metadata::MappingVersion;
use openehr_mapping_core::template::Generation;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ProfileUrl(String);
impl ProfileUrl {
#[must_use]
pub fn new(url: impl Into<String>) -> Self {
Self(url.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for ProfileUrl {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TemplateId(String);
impl TemplateId {
#[must_use]
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for TemplateId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ResourceType(String);
impl ResourceType {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self(name.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for ResourceType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Pin {
Pinned(String),
Unpinned,
}
impl Pin {
#[must_use]
pub fn new(version: Option<&str>) -> Self {
version.map_or(Self::Unpinned, |value| Self::Pinned(value.to_owned()))
}
#[must_use]
pub fn version(&self) -> Option<&str> {
match *self {
Self::Pinned(ref version) => Some(version),
Self::Unpinned => None,
}
}
#[must_use]
pub const fn is_unpinned(&self) -> bool {
matches!(*self, Self::Unpinned)
}
}
impl fmt::Display for Pin {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Pinned(ref version) => f.write_str(version),
Self::Unpinned => f.write_str("unpinned"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProfileBinding {
url: ProfileUrl,
version: Pin,
}
impl ProfileBinding {
#[must_use]
pub const fn new(url: ProfileUrl, version: Pin) -> Self {
Self { url, version }
}
#[must_use]
pub const fn url(&self) -> &ProfileUrl {
&self.url
}
#[must_use]
pub const fn version(&self) -> &Pin {
&self.version
}
}
impl fmt::Display for ProfileBinding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} version {}", self.url, self.version)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TemplateBinding {
id: TemplateId,
sem_ver: Pin,
generation: Generation,
}
impl TemplateBinding {
#[must_use]
pub const fn new(id: TemplateId, sem_ver: Pin, generation: Generation) -> Self {
Self {
id,
sem_ver,
generation,
}
}
#[must_use]
pub const fn id(&self) -> &TemplateId {
&self.id
}
#[must_use]
pub const fn sem_ver(&self) -> &Pin {
&self.sem_ver
}
#[must_use]
pub const fn generation(&self) -> Generation {
self.generation
}
}
impl fmt::Display for TemplateBinding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{} sem_ver {} generation {}",
self.id, self.sem_ver, self.generation
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModelBinding {
name: MappingName,
version: MappingVersion,
archetype: Option<ArchetypeId>,
revision: Pin,
extensions: Vec<MappingName>,
}
impl ModelBinding {
#[must_use]
pub const fn new(
name: MappingName,
version: MappingVersion,
archetype: Option<ArchetypeId>,
revision: Pin,
extensions: Vec<MappingName>,
) -> Self {
Self {
name,
version,
archetype,
revision,
extensions,
}
}
#[must_use]
pub const fn name(&self) -> &MappingName {
&self.name
}
#[must_use]
pub const fn version(&self) -> &MappingVersion {
&self.version
}
#[must_use]
pub const fn archetype(&self) -> Option<&ArchetypeId> {
self.archetype.as_ref()
}
#[must_use]
pub const fn revision(&self) -> &Pin {
&self.revision
}
#[must_use]
pub fn extensions(&self) -> &[MappingName] {
&self.extensions
}
}