1use serde::Serialize;
17use thiserror::Error;
18
19#[derive(Debug, Error, Serialize)]
20pub enum InputValidationError {
21 #[error("Invalid country code: {0}")]
22 InvalidCountryCode(String),
23 #[error("Invalid region code: {0}")]
24 InvalidRegionCode(String),
25 #[error("Unexpected region code: {0} - Country has no regions.")]
26 UnexpectedRegionCode(String),
27}
28
29#[derive(Debug, Error, Serialize)]
30pub enum DatabaseError {
31 #[error("Trade agreement not found: {0}")]
32 TradeAgreementNotFound(String),
33 #[error("Country not found: {0}")]
34 CountryNotFound(String),
35 #[error("Region not found: {0}")]
36 RegionNotFound(String),
37 #[error("VAT rate not found: {0}")]
38 VatRateNotFound(String),
39}
40
41#[derive(Debug, Error, Serialize)]
42pub enum ProcessingError {
43 #[error("Invalid input: {0}")]
44 InputValidationError(InputValidationError),
45 #[error("Database error: {0}")]
46 DatabaseError(DatabaseError),
47 #[error("Invalid amount")]
48 InvalidAmount,
49}
50
51impl From<InputValidationError> for ProcessingError {
52 fn from(err: InputValidationError) -> Self {
53 ProcessingError::InputValidationError(err)
54 }
55}
56
57impl From<DatabaseError> for ProcessingError {
58 fn from(err: DatabaseError) -> Self {
59 ProcessingError::DatabaseError(err)
60 }
61}