use std::collections::BTreeMap;
use crate::category::Category;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Provided,
Received,
}
impl Direction {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Provided => "provided",
Self::Received => "received",
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Mapping {
pub context: Option<String>,
pub template: String,
pub profile: Option<String>,
pub files: Vec<String>,
pub package: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Elements {
count: usize,
paths: BTreeMap<String, usize>,
}
impl Elements {
#[must_use]
pub fn new(count: usize, paths: BTreeMap<String, usize>) -> Self {
let named = paths
.values()
.fold(0_usize, |sum, held| sum.saturating_add(*held));
Self {
count: count.max(named),
paths,
}
}
pub fn add(&mut self, path: Option<&str>) {
self.count = self.count.saturating_add(1);
if let Some(path) = path {
let held = self.paths.entry(path.to_owned()).or_default();
*held = held.saturating_add(1);
}
}
pub fn extend(&mut self, other: &Self) {
self.count = self.count.saturating_add(other.count);
for (path, count) in &other.paths {
let held = self.paths.entry(path.clone()).or_default();
*held = held.saturating_add(*count);
}
}
#[must_use]
pub const fn count(&self) -> usize {
self.count
}
#[must_use]
pub const fn paths(&self) -> &BTreeMap<String, usize> {
&self.paths
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transformation {
pub direction: Direction,
pub category: Option<Category>,
pub mapping: Mapping,
pub terminology: Vec<String>,
pub transcoded: Elements,
pub untranscoded: Elements,
pub dropped: Elements,
}