swift_mt_message/fields/field56.rs
1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4/// **Field 56: Intermediary**
5///
6/// ## Purpose
7/// Specifies the financial institution through which the transaction must pass to reach
8/// the account with institution (Field 57A). This field defines the routing path for
9/// payment instructions, enabling proper routing through intermediary banks when direct
10/// relationships do not exist. Critical for straight-through processing and automated
11/// payment routing in complex banking networks.
12///
13/// ## Format Options Overview
14/// - **Option A**: BIC with optional party identifier - structured intermediary identification
15/// - **Option C**: Party identifier only - simplified intermediary reference
16/// - **Option D**: Party identifier with name/address - detailed intermediary information
17///
18/// ## Business Context Applications
19/// - **Payment Routing**: Defines intermediary path to reach beneficiary's bank
20/// - **Correspondent Networks**: Utilizes existing correspondent banking relationships
21/// - **Cross-Border Payments**: Essential for international payment routing
22/// - **Domestic Clearing**: Integration with national payment systems
23///
24/// ## Special Payment Method Codes
25/// ### Critical Routing Instructions
26/// - **//FW**: Fedwire routing - Required by US banks for Fedwire processing
27/// - **//RT**: Real-Time Gross Settlement - Binding instruction for RTGS systems
28/// - **//AU**: Australian payment system routing
29/// - **//IN**: Indian payment system routing
30///
31/// ### Code Usage Rules
32/// - **Single Usage**: Codes //FW, //AU, //IN, //RT should appear only once in Field 56A or 57A
33/// - **Binding Nature**: //RT code is binding and cannot be followed by other information
34/// - **System Integration**: Enables automated processing in national clearing systems
35/// - **Precedence**: Special codes take precedence over standard routing information
36///
37/// ## Network Validation Requirements
38/// - **BIC Registration**: All BIC codes must be registered financial institutions
39/// - **Routing Capability**: Intermediaries must provide routing services to destination
40/// - **System Support**: Must support specified payment method codes
41/// - **Currency Capability**: Must handle transaction currency and settlement
42///
43/// ## Routing Logic and Rules
44/// ### Direct vs. Intermediary Routing
45/// - **Direct Access**: When Sender has direct relationship with Account With Institution
46/// - **Intermediary Required**: When direct relationship does not exist or is inefficient
47/// - **Multi-Hop Routing**: Complex routing through multiple intermediaries
48/// - **Optimization**: Selection of most efficient routing path
49///
50/// ### Payment System Integration
51/// - **RTGS Systems**: Real-time gross settlement system routing
52/// - **ACH Networks**: Automated clearing house routing
53/// - **Wire Networks**: Wire transfer system routing
54/// - **Clearing Systems**: National and regional clearing system integration
55///
56/// ## Regional Payment System Support
57/// ### North American Systems
58/// - **Fedwire (//FW)**: US Federal Reserve wire transfer system
59/// - **ACH**: Automated Clearing House networks
60/// - **Canadian Systems**: Integration with Canadian payment networks
61///
62/// ### Asia-Pacific Systems
63/// - **Australian (//AU)**: Australian payment system integration
64/// - **Indian (//IN)**: Indian payment system routing
65/// - **Regional Networks**: ASEAN and other regional payment systems
66///
67/// ### European Systems
68/// - **TARGET2**: European Central Bank RTGS system
69/// - **SEPA**: Single Euro Payments Area routing
70/// - **National RTGS**: Country-specific RTGS systems
71///
72/// ## STP Processing Benefits
73/// - **Automated Routing**: System-driven routing based on intermediary identification
74/// - **Exception Reduction**: Proper routing reduces payment exceptions and delays
75/// - **Straight-Through Processing**: Enhanced STP through structured routing data
76/// - **System Integration**: Seamless integration with payment system networks
77///
78/// ## Error Prevention Guidelines
79/// - **Routing Validation**: Verify intermediary can route to destination
80/// - **System Compatibility**: Confirm intermediary supports required payment systems
81/// - **Code Verification**: Validate special payment method codes are appropriate
82/// - **Relationship Checking**: Verify Sender has relationship with intermediary
83///
84/// ## Related Fields Integration
85/// - **Field 57A**: Account With Institution (routing destination)
86/// - **Field 53A**: Sender's Correspondent (routing coordination)
87/// - **Field 32A**: Value Date, Currency, Amount (routing context)
88/// - **Field 72**: Sender to Receiver Information (routing instructions)
89///
90/// ## Compliance Framework
91/// - **Routing Documentation**: Complete routing path documentation
92/// - **Intermediary Due Diligence**: Enhanced due diligence on routing intermediaries
93/// - **Regulatory Compliance**: Meeting routing and settlement regulations
94/// - **Audit Trail**: Comprehensive routing audit trail maintenance
95///
96/// ## Performance Optimization
97/// - **Routing Efficiency**: Selection of optimal routing paths
98/// - **Cost Management**: Consideration of routing costs and fees
99/// - **Speed Optimization**: Fastest routing path selection
100/// - **Reliability**: Most reliable routing path selection
101///
102/// ## See Also
103/// - Swift FIN User Handbook: Intermediary Institution Specifications
104/// - Payment System Guides: National Payment System Routing
105/// - Correspondent Banking: Intermediary Routing Arrangements
106/// - Cross-Border Payments: International Routing Standards
107///
108/// **Field 56A: Intermediary (BIC with Party Identifier)**
109///
110/// Structured intermediary identification using BIC code with optional party identifier.
111/// Preferred option for automated payment routing and system integration.
112#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
113pub struct Field56A {
114 /// Optional party identifier for routing and payment method codes
115 ///
116 /// Format: \[/1!a\]\[/34x\] - Single character code + up to 34 character identifier
117 /// May contain special codes: //FW (Fedwire), //RT (RTGS), //AU (Australian), //IN (Indian)
118 #[component("[/1!a][/34x]")]
119 pub party_identifier: Option<String>,
120
121 /// Bank Identifier Code of the intermediary institution
122 ///
123 /// Format: 4!a2!a2!c\[3!c\] - 8 or 11 character BIC code
124 /// Must be registered financial institution with routing capability
125 #[component("4!a2!a2!c[3!c]")]
126 pub bic: String,
127}
128
129/// **Field 56C: Intermediary (Party Identifier Only)**
130///
131/// Simplified intermediary reference using party identifier only.
132/// Used when BIC is not required or available for routing purposes.
133#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
134pub struct Field56C {
135 /// Party identifier for intermediary routing
136 ///
137 /// Format: /34x - Mandatory slash prefix + up to 34 character identifier
138 /// Used for domestic routing codes and clearing system identifiers
139 #[component("/34x")]
140 pub party_identifier: String,
141}
142
143/// **Field 56D: Intermediary (Party Identifier with Name and Address)**
144///
145/// Detailed intermediary identification with full name and address information.
146/// Used when structured BIC identification is not available for intermediary.
147#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
148pub struct Field56D {
149 /// Optional party identifier for routing and payment method codes
150 ///
151 /// Format: \[/1!a\]\[/34x\] - Single character code + up to 34 character identifier
152 /// May contain special routing codes and clearing system identifiers
153 #[component("[/1!a][/34x]")]
154 pub party_identifier: Option<String>,
155
156 /// Name and address of the intermediary institution
157 ///
158 /// Format: 4*35x - Up to 4 lines of 35 characters each
159 /// Contains institution name, address, city, country details
160 #[component("4*35x")]
161 pub name_and_address: Vec<String>,
162}
163
164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
165pub enum Field56Intermediary {
166 A(Field56A),
167 C(Field56C),
168 D(Field56D),
169}
170
171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
172pub enum Field56IntermediaryAD {
173 A(Field56A),
174 D(Field56D),
175}