use alloc::boxed::Box;
use crate::types::{Currency, Period, RateType};
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum LookupError {
#[error("currency '{code}' is not published in HMRC {table} rates")]
UnknownCurrency { code: Box<str>, table: RateType },
#[error("no HMRC {table} rates for {period}{}", available_range(.available))]
PeriodNotAvailable {
table: RateType,
period: Period,
available: Option<(Period, Period)>,
},
#[error("'{currency}' has no HMRC {table} rate for {period}")]
NotInPeriod {
currency: Currency,
table: RateType,
period: Period,
},
}
fn available_range(available: &Option<(Period, Period)>) -> alloc::string::String {
use alloc::format;
match available {
Some((first, last)) => format!(" (available {first} to {last})"),
None => alloc::string::String::from(" (no data loaded)"),
}
}