1use chrono::NaiveDate;
2
3use crate::messages::{GetCardByIndexResponse, GetCardByIDResponse};
4use anyhow::Result;
5
6#[derive(Debug)]
7pub struct Card {
8 pub number: u32,
9 pub from: NaiveDate,
10 pub to: NaiveDate,
11 pub doors: Vec<u8>,
12}
13
14impl TryFrom<GetCardByIndexResponse> for Card {
15 type Error = anyhow::Error;
16 fn try_from(response: GetCardByIndexResponse) -> Result<Card> {
17 Ok(Card {
18 number: response.card_number,
19 from: response.from.try_into()?,
20 to: response.to.try_into()?,
21 doors: vec![
22 response.door_1,
23 response.door_2,
24 response.door_3,
25 response.door_4,
26 ],
27 })
28 }
29}
30
31impl TryFrom<GetCardByIDResponse> for Card {
32 type Error = anyhow::Error;
33 fn try_from(response: GetCardByIDResponse) -> Result<Card> {
34 Ok(Card {
35 number: response.card_number,
36 from: response.from.try_into()?,
37 to: response.to.try_into()?,
38 doors: vec![
39 response.door_1,
40 response.door_2,
41 response.door_3,
42 response.door_4,
43 ],
44 })
45 }
46}