summaryrefslogtreecommitdiff
path: root/src/types/account.rs
blob: 66796a633fc06f4b77446aabf22ea5d86a04df44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use super::ids::AccountId;
use super::path::MaterializedPath;

#[derive(PartialEq, Clone)]
pub enum AccountType {
    Asset,
    Liability,
    Equity,
    Revenue,
    Expense
}

#[derive(Clone)]
pub struct Account {
    account_id: AccountId,
    pub account_type: AccountType,
    pub name: String,
    pub description: String,
    pub path: MaterializedPath
}

impl Account {
    pub(crate) fn from_parts(account_id: AccountId, account_type: AccountType, name: String, description: String, path: MaterializedPath) -> Self {
        Account { account_id, account_type, name, description, path }
    }
    
    pub fn id(&self) -> AccountId { self.account_id }
}

pub struct NewAccount {
    pub account_type: AccountType,
    pub name: String,
    pub description: String,
    pub parent: Option<AccountId>
}

impl NewAccount {
    fn new(account_type: AccountType, name: impl Into<String>, description: impl Into<String>, parent: Option<AccountId>) -> NewAccount {
        NewAccount {
            account_type,
            name: name.into(),
            description: description.into(),
            parent
        }
    }
}