swift_mt_message/messages/mt920.rs
1use crate::fields::{field34::Field34F, *};
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// MT920: Request Message
6///
7/// ## Purpose
8/// Used to request specific account information or statement messages from another financial
9/// institution. This message allows institutions to request various types of account-related
10/// data including balances, statements, and transaction details on a per-account basis.
11///
12/// ## Scope
13/// This message is:
14/// - Sent between financial institutions to request account information
15/// - Used to request specific message types (MT940, MT941, MT942, MT950)
16/// - Applied for correspondent banking and account servicing relationships
17/// - Essential for account monitoring and reconciliation processes
18/// - Part of automated cash management and reporting systems
19///
20/// ## Key Features
21/// - **Message Type Specification**: Field 12 specifies the exact message type requested
22/// - **Account-Specific Requests**: Individual account identification for targeted requests
23/// - **Balance Requirements**: Specific balance information requirements using field 34F
24/// - **Repetitive Structure**: Multiple account requests in a single message
25/// - **Flexible Reporting**: Support for different statement and balance message types
26/// - **Automated Processing**: Designed for systematic and automated information requests
27///
28/// ## Common Use Cases
29/// - Requesting daily account statements (MT940)
30/// - Obtaining balance and transaction reports (MT941)
31/// - Requesting interim transaction statements (MT942)
32/// - Getting periodic balance statements (MT950)
33/// - Cash management system automation
34/// - Correspondent banking account monitoring
35/// - Regulatory reporting data collection
36/// - Liquidity management and planning
37///
38/// ## Message Structure
39/// ### Header Section
40/// - **20**: Transaction Reference (mandatory) - Unique reference for this request
41///
42/// ### Repetitive Sequence (MT920Sequence)
43/// Each sequence represents a request for a specific account and contains:
44/// - **12**: Message Type Requested (mandatory) - MT940, MT941, MT942, or MT950
45/// - **25**: Account Identification (mandatory) - Account for which information is requested
46/// - **34F**: Amount Fields (optional) - Specific balance or amount requirements
47///
48/// ## Field 12 - Message Types Requested
49/// Valid message types that can be requested:
50/// - **940**: Customer Statement Message (detailed transaction statement)
51/// - **941**: Balance Report Message (balance information with summary)
52/// - **942**: Interim Transaction Report (interim statement with real-time updates)
53/// - **950**: Statement Message (balance statement with transaction summary)
54///
55/// ## Field 34F - Amount Requirements
56/// Optional field that can specify:
57/// - **Debit Information**: When requesting debit balance details
58/// - **Credit Information**: When requesting credit balance details
59/// - **Currency Specification**: Specific currency for balance reporting
60/// - **Threshold Amounts**: Minimum amounts for transaction reporting
61///
62/// ## Network Validation Rules
63/// - **C1 Rule**: If message requested is 942, field 34F for debit must be present
64/// - **C2 Rule**: When both 34F fields present, first must be 'D' (debit), second must be 'C' (credit)
65/// - **C3 Rule**: Currency code must be consistent across all 34F entries
66/// - **Message Type Validation**: Field 12 must contain valid SWIFT MT type (940, 941, 942, 950)
67/// - **Reference Format**: Transaction references must follow SWIFT formatting standards
68/// - **Required Fields**: All mandatory fields must be present and properly formatted
69///
70/// ## Processing Workflow
71/// ### Request Processing
72/// 1. MT920 sent with specific account and message type requests
73/// 2. Receiving institution validates request parameters
74/// 3. Requested information extracted from account systems
75/// 4. Appropriate response message(s) generated and sent
76/// 5. Requesting institution processes received information
77///
78/// ### Automated Integration
79/// - Integration with cash management systems
80/// - Scheduled automated requests for regular reporting
81/// - Real-time balance monitoring capabilities
82/// - Exception-based reporting triggers
83///
84/// ## SRG2025 Status
85/// - **No Structural Changes**: MT920 format remains unchanged in SRG2025
86/// - **Enhanced Validation**: Additional validation for request accuracy and completeness
87/// - **Digital Integration**: Improved support for digital banking and API integration
88/// - **Real-time Capabilities**: Enhanced support for real-time information requests
89///
90/// ## Integration Considerations
91/// - **Banking Systems**: Direct integration with account management and core banking systems
92/// - **Cash Management**: Essential component of comprehensive cash management solutions
93/// - **API Gateway**: Often used in conjunction with modern API-based banking services
94/// - **Reporting Systems**: Critical input for automated reporting and compliance systems
95///
96/// ## Relationship to Other Messages
97/// - **Triggers**: MT940, MT941, MT942, MT950 response messages
98/// - **Supports**: Account monitoring, cash management, and reconciliation processes
99/// - **Complements**: Confirmation messages (MT900, MT910) for complete account visibility
100/// - **Integrates with**: Broader cash management and treasury operation workflows
101
102#[serde_swift_fields]
103#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
104#[validation_rules(MT920_VALIDATION_RULES)]
105pub struct MT920 {
106 #[field("20")]
107 pub field_20: Field20,
108
109 #[field("#")]
110 pub sequence: Vec<MT920Sequence>, // Sequence of Fields
111}
112
113#[serde_swift_fields]
114#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
115pub struct MT920Sequence {
116 #[field("12")]
117 pub field_12: Field12,
118
119 #[field("25")]
120 pub field_25: Field25A,
121
122 #[field("34F#1")]
123 pub field_34f_debit: Option<Field34F>,
124
125 #[field("34F#2")]
126 pub field_34f_credit: Option<Field34F>,
127}
128
129/// Validation rules for MT920 - Request Message
130const MT920_VALIDATION_RULES: &str = r#"{
131 "rules": [
132 {
133 "id": "C1",
134 "description": "If field 12 = 942, at least one occurrence of field 34F (Debit or Debit and Credit Floor Limit Indicator) must be present",
135 "condition": {
136 "all": [
137 {"var": "fields.#"},
138 {
139 "if": [
140 {"==": [{"var": "12.value"}, "942"]},
141 {
142 "or": [
143 {"exists": ["fields", "34F#1"]},
144 {"exists": ["fields", "34F#2"]}
145 ]
146 },
147 true
148 ]
149 }
150 ]
151 }
152 },
153 {
154 "id": "C2",
155 "description": "When both 34F fields are present: subfield 2 of the first must be D, subfield 2 of the second must be C. If only one 34F is present, subfield 2 must be omitted",
156 "condition": {
157 "all": [
158 {"var": "fields.#"},
159 {
160 "if": [
161 {
162 "and": [
163 {"exists": ["fields", "34F#1"]},
164 {"exists": ["fields", "34F#2"]}
165 ]
166 },
167 {
168 "and": [
169 {"==": [{"var": "34F#1.indicator"}, "D"]},
170 {"==": [{"var": "34F#2.indicator"}, "C"]}
171 ]
172 },
173 {
174 "if": [
175 {
176 "or": [
177 {
178 "and": [
179 {"exists": ["fields", "34F#1"]},
180 {"!": {"exists": ["fields", "34F#2"]}}
181 ]
182 },
183 {
184 "and": [
185 {"!": {"exists": ["fields", "34F#1"]}},
186 {"exists": ["fields", "34F#2"]}
187 ]
188 }
189 ]
190 },
191 {
192 "or": [
193 {
194 "and": [
195 {"exists": ["fields", "34F#1"]},
196 {"!": {"exists": ["fields", "34F#1", "indicator"]}}
197 ]
198 },
199 {
200 "and": [
201 {"exists": ["fields", "34F#2"]},
202 {"!": {"exists": ["fields", "34F#2", "indicator"]}}
203 ]
204 }
205 ]
206 },
207 true
208 ]
209 }
210 ]
211 }
212 ]
213 }
214 },
215 {
216 "id": "C3",
217 "description": "Currency code must be the same in each occurrence of field 34F within a sequence",
218 "condition": {
219 "all": [
220 {"var": "fields.#"},
221 {
222 "if": [
223 {
224 "and": [
225 {"exists": ["fields", "34F#1"]},
226 {"exists": ["fields", "34F#2"]}
227 ]
228 },
229 {"==": [
230 {"var": "34F#1.currency"},
231 {"var": "34F#2.currency"}
232 ]},
233 true
234 ]
235 }
236 ]
237 }
238 }
239 ]
240}"#;