swift_mt_message/fields/field21.rs
1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4/// **Field 21: Related Reference / Transaction Reference**
5///
6/// ## Purpose
7/// Specifies a unique reference assigned by the sending financial institution to unambiguously
8/// identify the transaction or instruction. This field serves as a cross-reference to link
9/// related messages and facilitates transaction tracking across the payment chain.
10///
11/// ## Format
12/// - **Swift Format**: `16x` (NoOption), `35x` (C, D, E options), `16x` (F, R options)
13/// - **Description**: Alphanumeric characters with specific length restrictions per option
14/// - **Character Set**: Letters, digits, and limited special characters (excluding consecutive slashes)
15///
16/// ## Presence
17/// - **Status**: Conditional/Optional depending on message type and sequence
18/// - **Swift Error Codes**: T26 (invalid characters), T50 (format violation)
19/// - **Usage Context**: Transaction identification and cross-referencing
20///
21/// ## Usage Rules
22/// - **Reference Uniqueness**: Must be unique within the context of the sending institution
23/// - **Cross-Reference**: Often used to link related instructions or provide trace information
24/// - **Slash Restrictions**: Must not start or end with slash, no consecutive slashes allowed
25/// - **Transaction Chain**: Enables tracking across multiple message exchanges
26///
27/// ## Network Validation Rules
28/// - **Character Validation**: Only alphanumeric and specific special characters allowed
29/// - **Length Validation**: Must not exceed maximum length for specific option
30/// - **Format Compliance**: Must follow Swift character set standards
31/// - **Slash Rules**: Proper slash usage for structured references
32///
33/// ## Field Options and Usage
34///
35/// ### NoOption (16x)
36/// - **Usage**: Basic transaction reference in customer payments (MT103)
37/// - **Length**: Up to 16 characters
38/// - **Purpose**: Simple transaction identification
39///
40/// ### Option C (35x)
41/// - **Usage**: Customer-specific references, often in treasury operations
42/// - **Length**: Up to 35 characters
43/// - **Purpose**: Extended reference capability for complex transactions
44///
45/// ### Option D (35x)
46/// - **Usage**: Deal reference in treasury and money market transactions
47/// - **Length**: Up to 35 characters
48/// - **Purpose**: Transaction identification in financial markets
49///
50/// ### Option E (35x)
51/// - **Usage**: Related reference for linked transactions
52/// - **Length**: Up to 35 characters
53/// - **Purpose**: Cross-referencing between related instructions
54///
55/// ### Option F (16x)
56/// - **Usage**: File reference for batch operations (MT102)
57/// - **Length**: Up to 16 characters
58/// - **Purpose**: Batch identification and grouping
59///
60/// ### Option R (16x)
61/// - **Usage**: Related file reference
62/// - **Length**: Up to 16 characters
63/// - **Purpose**: Linking to previously sent file references
64///
65/// ## Business Context
66/// - **Transaction Tracking**: Essential for audit trails and payment investigation
67/// - **Reconciliation**: Enables matching of instructions with confirmations
68/// - **STP Processing**: Facilitates automated processing and exception handling
69/// - **Regulatory Compliance**: Supports regulatory reporting and monitoring requirements
70///
71/// ## Examples
72/// ```logic
73/// :21:CUST/20250719/001 // Customer payment reference
74/// :21C:FX/USD/EUR/12345 // Treasury deal reference
75/// :21D:SPOT20250719001 // Deal reference for spot transaction
76/// :21E:REL/MT103/20250719 // Related transaction reference
77/// :21F:BATCH001 // File reference for batch
78/// :21R:RELBATCH001 // Related file reference
79/// ```
80///
81/// ## Regional Considerations
82/// - **European Payments**: SEPA reference standards compliance
83/// - **US Payments**: FedWire reference format considerations
84/// - **Asian Markets**: Local reference numbering schemes
85/// - **Cross-Border**: International reference coordination
86///
87/// ## Error Prevention
88/// - **Reference Validation**: Verify uniqueness within institutional context
89/// - **Format Checking**: Ensure compliance with character set restrictions
90/// - **Length Verification**: Confirm reference length within option limits
91/// - **Slash Validation**: Check proper slash usage and positioning
92///
93/// ## Related Fields
94/// - **Field 20**: Sender's Reference (primary transaction identifier)
95/// - **Field 11**: MT Reference (message-level reference)
96/// - **Field 72**: Sender to Receiver Information (additional reference details)
97/// - **Block Headers**: Message references in application headers
98///
99/// ## Transaction Lifecycle
100/// - **Initiation**: Original reference assignment by sending institution
101/// - **Processing**: Reference propagation through payment chain
102/// - **Confirmation**: Reference matching in return messages
103/// - **Settlement**: Reference inclusion in settlement confirmations
104///
105/// ## STP Compliance
106/// - **Automated Processing**: Reference format standardization for STP
107/// - **Exception Handling**: Reference-based transaction investigation
108/// - **Matching Logic**: Automated reference correlation across messages
109/// - **Quality Control**: Reference validation in STP gateways
110///
111/// ## Compliance and Audit
112/// - **Audit Trail**: Comprehensive transaction reference tracking
113/// - **Regulatory Reporting**: Reference inclusion in compliance reports
114/// - **Investigation Support**: Reference-based transaction reconstruction
115/// - **Documentation**: Reference preservation for regulatory periods
116///
117/// ## See Also
118/// - Swift FIN User Handbook: Reference Field Standards
119/// - MT Message Reference Guide: Field 21 Specifications
120/// - STP Guidelines: Reference Format Requirements
121/// - Payment Processing Standards: Transaction Identification
122///
123/// **Field 21 NoOption: Basic Transaction Reference**
124///
125/// Basic transaction reference used in customer payment instructions.
126/// Limited to 16 characters for simple transaction identification.
127#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
128pub struct Field21NoOption {
129 /// Transaction reference (up to 16 characters)
130 ///
131 /// Format: 16x - Alphanumeric with Swift character set restrictions
132 /// Must not start/end with slash or contain consecutive slashes
133 #[component("16x")]
134 pub reference: String,
135}
136
137/// **Field 21C: Customer-Specific Reference**
138///
139/// Extended reference capability for customer-specific transaction identification
140/// in treasury operations and complex financial transactions.
141#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
142pub struct Field21C {
143 /// Customer reference (up to 35 characters)
144 ///
145 /// Format: 35x - Extended alphanumeric reference for complex transactions
146 /// Used in treasury operations requiring detailed reference information
147 #[component("35x")]
148 pub reference: String,
149}
150
151/// **Field 21D: Deal Reference**
152///
153/// Deal reference for treasury and money market transactions, providing
154/// detailed identification for financial market operations.
155#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
156pub struct Field21D {
157 /// Deal reference (up to 35 characters)
158 ///
159 /// Format: 35x - Deal identification in treasury and money markets
160 /// Essential for tracking foreign exchange and derivatives transactions
161 #[component("35x")]
162 pub reference: String,
163}
164
165/// **Field 21E: Related Reference**
166///
167/// Related reference for linking transactions and instructions across
168/// multiple messages in a transaction chain.
169#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
170pub struct Field21E {
171 /// Related reference (up to 35 characters)
172 ///
173 /// Format: 35x - Cross-reference to link related instructions
174 /// Enables transaction correlation and audit trail maintenance
175 #[component("35x")]
176 pub reference: String,
177}
178
179/// **Field 21F: File Reference**
180///
181/// File reference for batch operations, enabling grouping and identification
182/// of multiple transactions processed together.
183#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
184pub struct Field21F {
185 /// File reference (up to 16 characters)
186 ///
187 /// Format: 16x - Batch identification for grouped transactions
188 /// Used in MT102 and other batch processing scenarios
189 #[component("16x")]
190 pub reference: String,
191}
192
193/// **Field 21R: Related File Reference**
194///
195/// Related file reference for linking to previously sent file references
196/// in batch processing scenarios.
197#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
198pub struct Field21R {
199 /// Related file reference (up to 16 characters)
200 ///
201 /// Format: 16x - Reference to previously sent file or batch
202 /// Enables correlation between related batch operations
203 #[component("16x")]
204 pub reference: String,
205}