swift_mt_message/messages/mt920.rs
1use crate::fields::*;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// # MT920: Request Message
6///
7/// This message is used by a financial institution to request specific types of statements
8/// or reports from another financial institution. This message enables automated
9/// request processing for account statements, balance reports, and transaction
10/// reports, facilitating efficient cash management and reconciliation processes.
11///
12/// ## Key Features
13/// - **Statement requests**: Requesting MT940 (customer statement) or MT950 (statement message)
14/// - **Balance reports**: Requesting MT941 (balance report)
15/// - **Interim reports**: Requesting MT942 (interim transaction report)
16/// - **Automated reporting**: Scheduled statement and report generation
17/// - **Cash management**: Regular balance and transaction monitoring
18/// - **Reconciliation**: Obtaining statements for reconciliation purposes
19///
20/// ## Field Structure
21/// All fields follow the enhanced macro system with proper validation rules.
22/// The message supports floor limit specification for MT942 requests.
23///
24/// ## Conditional Rules
25/// - **C1**: If Field 12 = '942', Field 34F for debit or debit/credit must be present
26/// - **C2**: When both Field 34F fields are present: first must have sign 'D', second must have sign 'C'
27/// - **C3**: Currency code must be same across all Field 34F entries in a message
28#[serde_swift_fields]
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
30#[validation_rules(MT920_VALIDATION_RULES)]
31pub struct MT920 {
32 /// **Transaction Reference Number** - Field 20
33 ///
34 /// Unique sender's reference identifying this specific request message.
35 /// Used throughout the request lifecycle for tracking, correlation with
36 /// response messages, and audit purposes.
37 #[field("20", mandatory)]
38 pub field_20: GenericReferenceField,
39
40 /// **Message Requested** - Field 12
41 ///
42 /// Specifies the type of SWIFT message being requested. This determines
43 /// the format and content of the response message that will be generated.
44 /// Valid values: 940, 941, 942, 950
45 #[field("12", mandatory)]
46 pub field_12: GenericTextField,
47
48 /// **Account Identification** - Field 25
49 ///
50 /// Identifies the specific account for which the statement or report
51 /// is being requested. Must be a valid account identifier that the
52 /// receiver can process and generate reports for.
53 #[field("25", mandatory)]
54 pub field_25: GenericTextField,
55
56 /// **Debit or Debit/Credit Floor Limit** - Field 34F (Optional, Conditional C1)
57 ///
58 /// Specifies the floor limit for debit transactions or combined debit/credit
59 /// transactions when requesting MT942 interim transaction reports. Transactions
60 /// above this limit will be included in the report.
61 #[field("34F_DEBIT", optional)]
62 pub field_34f_debit: Option<Field34F>,
63
64 /// **Credit Floor Limit Indicator** - Field 34F (Optional, Conditional C2)
65 ///
66 /// Specifies the floor limit for credit transactions when requesting MT942
67 /// interim transaction reports. Used in conjunction with debit floor limit
68 /// to provide comprehensive transaction filtering.
69 #[field("34F_CREDIT", optional)]
70 pub field_34f_credit: Option<Field34F>,
71}
72
73/// Enhanced validation rules for MT920
74const MT920_VALIDATION_RULES: &str = r#"{
75 "rules": [
76 {
77 "id": "C1",
78 "description": "If message requested is 942, Field 34F for debit must be present",
79 "condition": {
80 "if": [
81 {"==": [{"var": "field_12.value"}, "942"]},
82 {"var": "field_34f_debit.is_some"},
83 true
84 ]
85 }
86 },
87 {
88 "id": "C2",
89 "description": "When both 34F fields present: first must be 'D', second must be 'C'",
90 "condition": {
91 "if": [
92 {
93 "and": [
94 {"var": "field_34f_debit.is_some"},
95 {"var": "field_34f_credit.is_some"}
96 ]
97 },
98 {
99 "and": [
100 {"==": [{"var": "field_34f_debit.sign"}, "D"]},
101 {"==": [{"var": "field_34f_credit.sign"}, "C"]}
102 ]
103 },
104 true
105 ]
106 }
107 },
108 {
109 "id": "C3",
110 "description": "Currency code must be same across all 34F entries",
111 "condition": {
112 "if": [
113 {
114 "and": [
115 {"var": "field_34f_debit.is_some"},
116 {"var": "field_34f_credit.is_some"}
117 ]
118 },
119 {"==": [
120 {"var": "field_34f_debit.currency"},
121 {"var": "field_34f_credit.currency"}
122 ]},
123 true
124 ]
125 }
126 },
127 {
128 "id": "REF_FORMAT",
129 "description": "Transaction reference must not have invalid slash patterns",
130 "condition": {
131 "and": [
132 {"!": {"startsWith": [{"var": "field_20.value"}, "/"]}},
133 {"!": {"endsWith": [{"var": "field_20.value"}, "/"]}},
134 {"!": {"includes": [{"var": "field_20.value"}, "//"]}}
135 ]
136 }
137 },
138 {
139 "id": "MESSAGE_TYPE_VALID",
140 "description": "Message requested must be valid SWIFT MT type",
141 "condition": {
142 "in": [
143 {"var": "field_12.value"},
144 ["940", "941", "942", "950"]
145 ]
146 }
147 },
148 {
149 "id": "REQUIRED_FIELDS",
150 "description": "All mandatory fields must be present and non-empty",
151 "condition": {
152 "and": [
153 {"!=": [{"var": "field_20.value"}, ""]},
154 {"!=": [{"var": "field_12.value"}, ""]},
155 {"!=": [{"var": "field_25.value"}, ""]}
156 ]
157 }
158 }
159 ]
160}"#;