swift_mt_message/fields/field52.rs
1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4/// **Field 52: Ordering Institution / Account Servicing Institution**
5///
6/// ## Purpose
7/// Specifies the financial institution of the ordering customer when different from
8/// the Sender, or identifies the account servicing institution in various transaction
9/// contexts. This field enables proper institutional identification and routing in
10/// complex multi-party transactions where the ordering customer's bank differs from
11/// the message originator. Critical for correspondent banking and institutional relationships.
12///
13/// ## Format Options Overview
14/// - **Option A**: BIC with optional party identifier - structured institutional identification
15/// - **Option B**: Party identifier with location - domestic routing information
16/// - **Option C**: Party identifier only - simplified institutional reference
17/// - **Option D**: Party identifier with name/address - detailed institutional information
18///
19/// ## Business Context Applications
20/// - **Ordering Institution**: When ordering customer's bank differs from message sender
21/// - **Account Servicing**: Institution maintaining the ordering customer's account
22/// - **Correspondent Banking**: Institutional relationships in cross-border payments
23/// - **Multi-Party Transactions**: Complex routing scenarios requiring institutional clarity
24///
25/// ## Network Validation Requirements
26/// - **BIC Registration**: All BIC codes must be registered financial institutions
27/// - **Clearing Codes**: National clearing codes must be valid for respective countries
28/// - **Format Compliance**: Exact adherence to option-specific format requirements
29/// - **Institutional Validity**: Referenced institutions must be reachable and operational
30///
31/// ## National Clearing System Support
32/// ### European Systems
33/// - **AT (Austria)**: Bankleitzahl - 5!n format
34/// - **BL (Germany)**: Bankleitzahl - 8!n format
35/// - **ES (Spain)**: Spanish Domestic - 8..9n format
36/// - **GR (Greece)**: HEBIC - 7!n format
37/// - **IE (Ireland)**: NSC - 6!n format
38/// - **IT (Italy)**: Italian Domestic - 10!n format
39/// - **PL (Poland)**: KNR - 8!n format
40/// - **PT (Portugal)**: Portuguese - 8!n format
41/// - **SC (UK)**: Sort Code - 6!n format
42///
43/// ### North American Systems
44/// - **CC (Canada)**: Canadian Routing - 9!n format
45/// - **FW (US)**: Fedwire - without 9 digit code
46///
47/// ### Asia-Pacific Systems
48/// - **AU (Australia)**: BSB - 6!n format
49/// - **CN (China)**: CNAPS - 12..14n format
50/// - **HK (Hong Kong)**: Hong Kong - 3!n format
51/// - **IN (India)**: IFSC - 11!c format
52///
53/// ## Regional Considerations
54/// - **European Payments**: SEPA routing and TARGET2 integration
55/// - **US Payments**: Fedwire and ACH routing requirements
56/// - **Asian Markets**: Local clearing system compliance
57/// - **Cross-Border**: International correspondent banking arrangements
58///
59/// ## STP Processing Benefits
60/// - **Automated Routing**: System-driven institutional routing based on clear identification
61/// - **Exception Reduction**: Proper institutional identification reduces manual intervention
62/// - **Straight-Through Processing**: Enhanced STP rates through structured data
63/// - **Risk Mitigation**: Clear institutional accountability and routing paths
64///
65/// ## Error Prevention Guidelines
66/// - **BIC Validation**: Verify all BIC codes are registered and reachable
67/// - **Code Verification**: Confirm national clearing codes are current and valid
68/// - **Format Checking**: Ensure exact compliance with option format requirements
69/// - **Institutional Verification**: Confirm referenced institutions can process transactions
70///
71/// ## Related Fields Integration
72/// - **Field 50A/K**: Ordering Customer (institutional customer relationship)
73/// - **Field 53A**: Sender's Correspondent (reimbursement routing)
74/// - **Field 57A**: Account With Institution (beneficiary institutional relationship)
75/// - **Field 72**: Sender to Receiver Information (additional institutional details)
76///
77/// ## Compliance Framework
78/// - **Regulatory Identification**: Clear institutional identification for compliance
79/// - **Audit Documentation**: Complete institutional routing trail
80/// - **Risk Management**: Proper institutional identification for risk assessment
81/// - **Investigation Support**: Clear institutional details for compliance reviews
82///
83/// ## See Also
84/// - Swift FIN User Handbook: Ordering Institution Specifications
85/// - National Clearing Code Directory: Country-Specific Routing Codes
86/// - Correspondent Banking Guidelines: Institutional Relationship Standards
87/// - BIC Directory: Registered Financial Institution Codes
88///
89/// **Field 52A: Ordering Institution (BIC with Party Identifier)**
90///
91/// Structured institutional identification using BIC code with optional party identifier.
92/// Preferred option for automated processing and correspondent banking.
93#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
94pub struct Field52A {
95 /// Optional party identifier for clearing system or account reference
96 ///
97 /// Format: \[/1!a/34x\] - Single character code + up to 34 character identifier
98 /// Used for national clearing codes and institutional account references
99 #[component("[/1!a/34x]")]
100 pub party_identifier: Option<String>,
101
102 /// Bank Identifier Code of the ordering institution
103 ///
104 /// Format: 4!a2!a2!c\[3!c\] - 8 or 11 character BIC code
105 /// Must be registered financial institution BIC
106 #[component("4!a2!a2!c[3!c]")]
107 pub bic: String,
108}
109
110/// **Field 52B: Ordering Institution (Party Identifier with Location)**
111///
112/// Domestic routing information using party identifier and location details.
113/// Used for national clearing systems requiring location-based routing.
114#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
115pub struct Field52B {
116 /// Optional party identifier for clearing system or account reference
117 ///
118 /// Format: \[/1!a\]\[/34x\] - Single character code + up to 34 character identifier
119 /// Used for domestic clearing systems and institutional references
120 #[component("[/1!a][/34x]")]
121 pub party_identifier: Option<String>,
122
123 /// Location information for domestic routing
124 ///
125 /// Format: \[35x\] - Up to 35 character location identifier
126 /// Used for location-based routing within domestic systems
127 #[component("[35x]")]
128 pub location: Option<String>,
129}
130
131/// **Field 52C: Ordering Institution (Party Identifier Only)**
132///
133/// Simplified institutional reference using party identifier only.
134/// Used when BIC is not required or available for institutional identification.
135#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
136pub struct Field52C {
137 /// Party identifier for institutional reference
138 ///
139 /// Format: /34x - Mandatory slash prefix + up to 34 character identifier
140 /// Used for domestic institutional references and clearing codes
141 #[component("/34x")]
142 pub party_identifier: String,
143}
144
145/// **Field 52D: Ordering Institution (Party Identifier with Name and Address)**
146///
147/// Detailed institutional identification with full name and address information.
148/// Used when structured BIC identification is not available or sufficient.
149#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
150pub struct Field52D {
151 /// Optional party identifier for clearing system or account reference
152 ///
153 /// Format: \[/1!a\]\[/34x\] - Single character code + up to 34 character identifier
154 /// Used for domestic clearing systems and institutional references
155 #[component("[/1!a][/34x]")]
156 pub party_identifier: Option<String>,
157
158 /// Name and address of the ordering institution
159 ///
160 /// Format: 4*35x - Up to 4 lines of 35 characters each
161 /// Contains institution name, address, city, country details
162 #[component("4*35x")]
163 pub name_and_address: Vec<String>,
164}
165
166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
167pub enum Field52AccountServicingInstitution {
168 A(Field52A),
169 C(Field52C),
170}
171
172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
173pub enum Field52OrderingInstitution {
174 A(Field52A),
175 D(Field52D),
176}
177
178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
179pub enum Field52CreditorBank {
180 A(Field52A),
181 C(Field52C),
182 D(Field52D),
183}
184
185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
186pub enum Field52DrawerBank {
187 A(Field52A),
188 B(Field52B),
189 D(Field52D),
190}