//! The categories the app offers. A category is an id; the label is what the app shows. pub const UNCATEGORISED: &str = "uncategorised"; /// Money between your own accounts: never spending. pub const TRANSFERS: &str = "transfers"; pub const INCOME: &str = "income"; /// Categories a monthly plan cannot be for: money in, money moved, and money not yet sorted. pub const NOT_PLANNABLE: [&str; 3] = [INCOME, TRANSFERS, UNCATEGORISED]; /// The most a category's monthly plan can be: 100 000 000 CZK, far from any sum overflowing. pub const MAX_PLAN: crate::money::Haler = crate::money::Haler(10_000_000_000); /// `(id, label)` in the order the app lists them. pub const DEFAULT: &[(&str, &str)] = &[ ("groceries", "Groceries"), ("eating-out", "Eating out"), ("transport", "Transport"), ("housing", "Housing"), ("utilities", "Utilities"), ("subscriptions", "Subscriptions"), ("shopping", "Shopping"), ("health", "Health"), ("kids", "Kids"), ("fun", "Fun"), ("travel", "Travel"), ("gifts", "Gifts"), (INCOME, "Income"), (TRANSFERS, "Transfers"), ("other", "Other"), (UNCATEGORISED, "Uncategorised"), ]; /// A category id is lowercase ASCII letters, digits and `-`, 1–40 characters. pub fn is_valid(id: &str) -> bool { (1..=40).contains(&id.len()) && id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-') } pub fn label(id: &str) -> &str { DEFAULT.iter().find(|(i, _)| *i == id).map(|(_, l)| *l).unwrap_or(id) }