Skip to main content

wave_api/models/
common.rs

1use rust_decimal::Decimal;
2use serde::Deserialize;
3
4use crate::enums::{CountryCode, CurrencyCode};
5
6/// Monetary value with currency.
7#[derive(Debug, Clone, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Money {
10    /// Value as a string representation (e.g. "100.00").
11    pub value: String,
12    /// Currency.
13    pub currency: Currency,
14}
15
16impl Money {
17    /// Parse the value as a Decimal.
18    pub fn decimal(&self) -> Result<Decimal, rust_decimal::Error> {
19        self.value.parse()
20    }
21}
22
23/// A currency.
24#[derive(Debug, Clone, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct Currency {
27    pub code: CurrencyCode,
28    pub symbol: String,
29    pub name: String,
30    pub plural: Option<String>,
31    pub exponent: Option<i32>,
32}
33
34/// A country.
35#[derive(Debug, Clone, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct Country {
38    pub code: CountryCode,
39    pub name: String,
40    pub name_with_article: Option<String>,
41    pub currency: Option<Currency>,
42    pub provinces: Option<Vec<Province>>,
43}
44
45/// A state/province/region.
46#[derive(Debug, Clone, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct Province {
49    pub code: String,
50    pub name: String,
51}
52
53/// An address.
54#[derive(Debug, Clone, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct Address {
57    pub address_line1: Option<String>,
58    pub address_line2: Option<String>,
59    pub city: Option<String>,
60    pub province: Option<Province>,
61    pub country: Option<Country>,
62    pub postal_code: Option<String>,
63}
64
65/// Shipping details for customers and vendors.
66#[derive(Debug, Clone, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct ShippingDetails {
69    pub name: Option<String>,
70    pub address: Option<Address>,
71    pub phone: Option<String>,
72    pub instructions: Option<String>,
73}