ynab_api/models/
hybrid_transaction.rs

1/*
2 * YNAB API Endpoints
3 *
4 * Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body.  API Documentation is at https://api.ynab.com
5 *
6 * The version of the OpenAPI document: 1.72.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct HybridTransaction {
16    #[serde(rename = "id")]
17    pub id: String,
18    /// The transaction date in ISO format (e.g. 2016-12-01)
19    #[serde(rename = "date")]
20    pub date: String,
21    /// The transaction amount in milliunits format
22    #[serde(rename = "amount")]
23    pub amount: i64,
24    #[serde(rename = "memo", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
25    pub memo: Option<Option<String>>,
26    #[serde(rename = "cleared")]
27    pub cleared: models::TransactionClearedStatus,
28    /// Whether or not the transaction is approved
29    #[serde(rename = "approved")]
30    pub approved: bool,
31    #[serde(rename = "flag_color", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
32    pub flag_color: Option<Option<models::TransactionFlagColor>>,
33    /// The customized name of a transaction flag
34    #[serde(rename = "flag_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
35    pub flag_name: Option<Option<String>>,
36    #[serde(rename = "account_id")]
37    pub account_id: uuid::Uuid,
38    #[serde(rename = "payee_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
39    pub payee_id: Option<Option<uuid::Uuid>>,
40    #[serde(rename = "category_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
41    pub category_id: Option<Option<uuid::Uuid>>,
42    /// If a transfer transaction, the account to which it transfers
43    #[serde(rename = "transfer_account_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
44    pub transfer_account_id: Option<Option<uuid::Uuid>>,
45    /// If a transfer transaction, the id of transaction on the other side of the transfer
46    #[serde(rename = "transfer_transaction_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
47    pub transfer_transaction_id: Option<Option<String>>,
48    /// If transaction is matched, the id of the matched transaction
49    #[serde(rename = "matched_transaction_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
50    pub matched_transaction_id: Option<Option<String>>,
51    /// If the transaction was imported, this field is a unique (by account) import identifier.  If this transaction was imported through File Based Import or Direct Import and not through the API, the import_id will have the format: 'YNAB:[milliunit_amount]:[iso_date]:[occurrence]'.  For example, a transaction dated 2015-12-30 in the amount of -$294.23 USD would have an import_id of 'YNAB:-294230:2015-12-30:1'.  If a second transaction on the same account was imported and had the same date and same amount, its import_id would be 'YNAB:-294230:2015-12-30:2'.
52    #[serde(rename = "import_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
53    pub import_id: Option<Option<String>>,
54    /// If the transaction was imported, the payee name that was used when importing and before applying any payee rename rules
55    #[serde(rename = "import_payee_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
56    pub import_payee_name: Option<Option<String>>,
57    /// If the transaction was imported, the original payee name as it appeared on the statement
58    #[serde(rename = "import_payee_name_original", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
59    pub import_payee_name_original: Option<Option<String>>,
60    /// If the transaction is a debt/loan account transaction, the type of transaction
61    #[serde(rename = "debt_transaction_type", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
62    pub debt_transaction_type: Option<Option<DebtTransactionType>>,
63    /// Whether or not the transaction has been deleted.  Deleted transactions will only be included in delta requests.
64    #[serde(rename = "deleted")]
65    pub deleted: bool,
66    /// Whether the hybrid transaction represents a regular transaction or a subtransaction
67    #[serde(rename = "type")]
68    pub r#type: Type,
69    /// For subtransaction types, this is the id of the parent transaction.  For transaction types, this id will be always be null.
70    #[serde(rename = "parent_transaction_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
71    pub parent_transaction_id: Option<Option<String>>,
72    #[serde(rename = "account_name")]
73    pub account_name: String,
74    #[serde(rename = "payee_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
75    pub payee_name: Option<Option<String>>,
76    /// The name of the category.  If a split transaction, this will be 'Split'.
77    #[serde(rename = "category_name", skip_serializing_if = "Option::is_none")]
78    pub category_name: Option<String>,
79}
80
81impl HybridTransaction {
82    pub fn new(id: String, date: String, amount: i64, cleared: models::TransactionClearedStatus, approved: bool, account_id: uuid::Uuid, deleted: bool, r#type: Type, account_name: String) -> HybridTransaction {
83        HybridTransaction {
84            id,
85            date,
86            amount,
87            memo: None,
88            cleared,
89            approved,
90            flag_color: None,
91            flag_name: None,
92            account_id,
93            payee_id: None,
94            category_id: None,
95            transfer_account_id: None,
96            transfer_transaction_id: None,
97            matched_transaction_id: None,
98            import_id: None,
99            import_payee_name: None,
100            import_payee_name_original: None,
101            debt_transaction_type: None,
102            deleted,
103            r#type,
104            parent_transaction_id: None,
105            account_name,
106            payee_name: None,
107            category_name: None,
108        }
109    }
110}
111/// If the transaction is a debt/loan account transaction, the type of transaction
112#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
113pub enum DebtTransactionType {
114    #[serde(rename = "payment")]
115    Payment,
116    #[serde(rename = "refund")]
117    Refund,
118    #[serde(rename = "fee")]
119    Fee,
120    #[serde(rename = "interest")]
121    Interest,
122    #[serde(rename = "escrow")]
123    Escrow,
124    #[serde(rename = "balanceAdjustment")]
125    BalanceAdjustment,
126    #[serde(rename = "credit")]
127    Credit,
128    #[serde(rename = "charge")]
129    Charge,
130}
131
132impl Default for DebtTransactionType {
133    fn default() -> DebtTransactionType {
134        Self::Payment
135    }
136}
137/// Whether the hybrid transaction represents a regular transaction or a subtransaction
138#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
139pub enum Type {
140    #[serde(rename = "transaction")]
141    Transaction,
142    #[serde(rename = "subtransaction")]
143    Subtransaction,
144}
145
146impl Default for Type {
147    fn default() -> Type {
148        Self::Transaction
149    }
150}
151