//! Both tariffs and CDRs can be linted - a term borrowed from software development where
//! linting is the act of flagging common errors, bugs, dangerous constructs and
//! stylistic flaws in a some code or data.
//!
//! The term originates from the English word `lint`, the tiny pieces of fiber and fluff that are
//! shed by clothing and trapped in a washing machines filter.
//!
//! Use [`tariff::lint`](crate::tariff::lint) to lint a tariff.

pub mod tariff;

/// Lint the given tariff and return a report of any `Warning`s found.
pub(crate) fn tariff(tariff: &crate::tariff::Versioned<'_>) -> tariff::Report {
    tariff::lint(tariff)
}

/// A container for items in a list that can be linted as an invalid item.
enum Item<T> {
    /// The item is invalid and can be ignored.
    Invalid,
    /// The item is valid and can be further inspected.
    Valid(T),
}

/// Convert an `Option<T>` into an `Item<T>`.
impl<T> From<Option<T>> for Item<T> {
    fn from(value: Option<T>) -> Self {
        match value {
            Some(v) => Item::Valid(v),
            None => Item::Invalid,
        }
    }
}

/// Convert an `Item<T>` into an `Option<T>`.
impl<T> From<Item<T>> for Option<T> {
    fn from(value: Item<T>) -> Self {
        match value {
            Item::Invalid => None,
            Item::Valid(v) => Some(v),
        }
    }
}
