swift_mt_message/messages/mt942.rs
1use crate::fields::*;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// MT942: Interim Transaction Report
6///
7/// ## Purpose
8/// Used to report interim account information including real-time or intraday transaction
9/// details and balance updates. This message provides timely account information between
10/// regular statement periods for enhanced cash management and liquidity monitoring.
11///
12/// ## Scope
13/// This message is:
14/// - Sent for real-time or intraday account reporting
15/// - Used when immediate transaction visibility is required
16/// - Applied for active cash management and treasury operations
17/// - Essential for intraday liquidity management and position monitoring
18/// - Part of real-time cash management and payment system integration
19///
20/// ## Key Features
21/// - **Real-time Reporting**: Immediate transaction and balance information
22/// - **Intraday Updates**: Multiple reports possible within a single business day
23/// - **Balance Limits**: Credit and debit limit information for account management
24/// - **Transaction Details**: Individual transaction entries with real-time processing
25/// - **Summary Information**: Debit and credit entry summaries for quick analysis
26/// - **Available Balance**: Current available balance for immediate decision making
27///
28/// ## Common Use Cases
29/// - Intraday liquidity monitoring
30/// - Real-time cash position management
31/// - Payment system integration
32/// - Overdraft and credit limit monitoring
33/// - High-frequency trading account management
34/// - Treasury operations requiring immediate visibility
35/// - Risk management and exposure monitoring
36/// - Automated cash sweeping and positioning
37///
38/// ## Field Structure
39/// - **20**: Transaction Reference (mandatory) - Unique report reference
40/// - **21**: Related Reference (optional) - Reference to related period or statement
41/// - **25**: Account Identification (mandatory) - Account being reported
42/// - **28C**: Statement Number/Sequence (mandatory) - Report numbering
43/// - **34F**: Debit Floor Limit (mandatory) - Minimum debit amount for reporting
44/// - **34F**: Credit Ceiling Limit (optional) - Maximum credit limit information
45/// - **13D**: Date/Time Indication (mandatory) - Precise timing of report
46/// - **Statement Lines**: Repetitive sequence of transaction details
47/// - **90D**: Number/Sum of Debit Entries (optional) - Debit transaction summary
48/// - **90C**: Number/Sum of Credit Entries (optional) - Credit transaction summary
49/// - **86**: Information to Account Owner (optional) - Additional transaction information
50///
51/// ## Network Validation Rules
52/// - **Currency Consistency**: All balance and limit fields must use consistent currency
53/// - **Entry Currency Consistency**: Entry summaries must use same currency as balances
54/// - **Reference Format**: Transaction references must follow SWIFT standards
55/// - **Required Fields**: All mandatory fields must be present and properly formatted
56/// - **Real-time Constraints**: Timing information must reflect current processing
57///
58/// ## SRG2025 Status
59/// - **Structural Changes**: None - MT942 format remains unchanged in SRG2025
60/// - **Validation Updates**: Additional validation for real-time reporting accuracy
61/// - **Processing Improvements**: Improved support for real-time banking platforms
62/// - **Compliance Notes**: Enhanced support for modern payment system APIs
63///
64/// ## Integration Considerations
65/// - **Banking Systems**: Real-time integration with payment processing and account management systems
66/// - **Treasury Systems**: Critical input for intraday liquidity management and cash positioning
67/// - **API Integration**: Essential for modern real-time banking and payment system integration
68/// - **Risk Management**: Key component for real-time exposure monitoring and limit management
69///
70/// ## Relationship to Other Messages
71/// - **Triggered by**: MT920 (Request Message) for real-time account information requests
72/// - **Complements**: MT940 (daily statements) and MT941 (balance reports) with real-time updates
73/// - **Supports**: Intraday liquidity management, payment processing, and real-time cash management
74/// - **Integrates with**: Real-time payment systems, treasury platforms, and risk management systems
75
76#[serde_swift_fields]
77#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
78#[validation_rules(MT942_VALIDATION_RULES)]
79pub struct MT942 {
80 #[field("20")]
81 pub field_20: Field20,
82
83 #[field("21")]
84 pub field_21: Option<Field21NoOption>,
85
86 #[field("25")]
87 pub field_25: Field25AccountIdentification,
88
89 #[field("28C")]
90 pub field_28c: Field28C,
91
92 #[field("34F#1")]
93 pub field_34f_debit_limit: Field34F,
94
95 #[field("34F#2")]
96 pub field_34f_credit_limit: Option<Field34F>,
97
98 #[field("13D")]
99 pub field_13d: Field13D,
100
101 #[field("#")]
102 pub statement_lines: Vec<MT942StatementLine>,
103
104 #[field("90D")]
105 pub field_90d: Option<Field90D>,
106
107 #[field("90C")]
108 pub field_90c: Option<Field90C>,
109
110 #[field("86")]
111 pub field_86: Option<Field86>,
112}
113
114#[serde_swift_fields]
115#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
116pub struct MT942StatementLine {
117 #[field("61")]
118 pub field_61: Option<Field61>,
119
120 #[field("86")]
121 pub field_86: Option<Field86>,
122}
123
124/// Validation rules for MT942 - Interim Transaction Report
125const MT942_VALIDATION_RULES: &str = r#"{
126 "rules": [
127 {
128 "id": "C1",
129 "description": "The first two characters of the three-character currency code in fields 34F, 61, 90D, and 90C must be the same for all occurrences",
130 "condition": {
131 "and": [
132 {"exists": ["fields", "34F#1"]},
133 {
134 "if": [
135 {"exists": ["fields", "34F#2"]},
136 {"==": [
137 {"substr": [{"var": "fields.34F#1.currency"}, 0, 2]},
138 {"substr": [{"var": "fields.34F#2.currency"}, 0, 2]}
139 ]},
140 true
141 ]
142 },
143 {
144 "if": [
145 {"exists": ["fields", "90D"]},
146 {"==": [
147 {"substr": [{"var": "fields.34F#1.currency"}, 0, 2]},
148 {"substr": [{"var": "fields.90D.currency"}, 0, 2]}
149 ]},
150 true
151 ]
152 },
153 {
154 "if": [
155 {"exists": ["fields", "90C"]},
156 {"==": [
157 {"substr": [{"var": "fields.34F#1.currency"}, 0, 2]},
158 {"substr": [{"var": "fields.90C.currency"}, 0, 2]}
159 ]},
160 true
161 ]
162 },
163 {
164 "if": [
165 {">=": [{"length": {"var": "fields.#"}}, 1]},
166 {
167 "all": [
168 {"var": "fields.#"},
169 {
170 "if": [
171 {"exists": ["fields", "61"]},
172 {"==": [
173 {"substr": [{"var": "fields.34F#1.currency"}, 0, 2]},
174 {"substr": [{"var": "61.currency"}, 0, 2]}
175 ]},
176 true
177 ]
178 }
179 ]
180 },
181 true
182 ]
183 }
184 ]
185 }
186 }
187 ]
188}"#;