rtm_core/models/
transaction.rs

1use super::{Amount, ClientId, TransactionId};
2
3#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
4#[must_use]
5pub enum TransactionKind {
6    Deposit,
7    Withdrawal,
8}
9
10/// Represents an accounting operation that deals with the actual money.
11#[derive(Debug)]
12#[must_use]
13pub struct Transaction {
14    client_id: ClientId,
15    id: TransactionId,
16    amount: Amount,
17    kind: TransactionKind,
18}
19
20impl Transaction {
21    pub const fn new(client_id: ClientId, id: TransactionId, amount: Amount, kind: TransactionKind) -> Self {
22        Self {
23            client_id,
24            id,
25            amount,
26            kind,
27        }
28    }
29
30    pub const fn id(&self) -> TransactionId {
31        self.id
32    }
33
34    pub const fn client_id(&self) -> ClientId {
35        self.client_id
36    }
37
38    pub const fn kind(&self) -> TransactionKind {
39        self.kind
40    }
41
42    pub const fn amount(&self) -> &Amount {
43        &self.amount
44    }
45}