use chrono::{DateTime, Utc};
use serde::Deserialize;
use crate::endpoints::utils::empty_string_as_none;
mod list;
pub use list::Request as List;
mod deposit;
pub use deposit::Request as Deposit;
mod withdraw;
pub use withdraw::Request as Withdraw;
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Pot {
pub id: String,
pub name: String,
#[serde(deserialize_with = "empty_string_as_none")]
pub style: Option<String>,
pub balance: i64,
pub currency: String,
#[serde(default)]
pub goal_amount: Option<i64>,
pub current_account_id: String,
pub created: DateTime<Utc>,
pub updated: DateTime<Utc>,
pub deleted: bool,
}
#[cfg(test)]
mod tests {
use super::Pot;
#[test]
fn deserialise() {
let raw = r#"
{
"id": "pot_1234",
"name": "Savings",
"style": "teal",
"balance": 10,
"currency": "GBP",
"goal_amount": 1000000,
"type": "flexible_savings",
"product_id": "XXX",
"current_account_id": "acc_1234",
"cover_image_url": "",
"isa_wrapper": "ISA",
"round_up": false,
"round_up_multiplier": null,
"is_tax_pot": false,
"created": "2019-04-28T06:36:54.318Z",
"updated": "2019-05-11T00:31:04.256Z",
"deleted": false,
"locked": false,
"charity_id": "",
"available_for_bills": false
}
"#;
serde_json::from_str::<Pot>(raw).expect("couldn't decode Pot from json");
}
}