swift_mt_message/fields/field25.rs
1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4/// **Field 25: Account Identification / Authorisation**
5///
6/// ## Purpose
7/// Provides account identification or authorization information for payment instructions.
8/// This field serves dual purposes: identifying accounts for payment processing and
9/// providing security authorization codes between the ordering customer and the
10/// account servicing financial institution.
11///
12/// ## Format
13/// - **Swift Format**: `35x` (NoOption), `/34x` (Option A), `35x` + `4!a2!a2!c[3!c]` (Option P)
14/// - **Description**: Account identifier or authorization code with optional BIC
15/// - **Character Set**: Alphanumeric characters following Swift standards
16///
17/// ## Presence
18/// - **Status**: Optional in most contexts, mandatory when account identification required
19/// - **Swift Error Codes**: T61 (invalid account format), C05 (invalid BIC)
20/// - **Usage Context**: Account services and authorization verification
21///
22/// ## Usage Rules
23/// - **Account Identification**: Specifies account to be debited or credited
24/// - **Authorization Security**: Contains security provisions between customer and institution
25/// - **Format Selection**: Choose appropriate option based on account identification needs
26/// - **BIC Validation**: When BIC provided, must be valid financial institution identifier
27///
28/// ## Network Validation Rules
29/// - **Account Format**: Must conform to institutional account numbering standards
30/// - **BIC Validation**: BIC must be registered financial institution code
31/// - **Character Validation**: Only permitted characters in Swift character set
32/// - **Length Compliance**: Must not exceed maximum field length restrictions
33///
34/// ## Field Options and Usage
35///
36/// ### NoOption (35x) - Authorisation
37/// - **Usage**: Security authorization codes and digital signatures
38/// - **Length**: Up to 35 characters
39/// - **Purpose**: Authentication between customer and account servicing institution
40/// - **Security Context**: Electronic device codes, digital signatures, or agreed tokens
41///
42/// ### Option A (/34x) - Account Identifier
43/// - **Usage**: Simple account identification with slash prefix
44/// - **Length**: Up to 34 characters (excluding slash)
45/// - **Purpose**: Basic account identification for payment processing
46/// - **Format**: Slash followed by account identifier
47///
48/// ### Option P (35x + BIC) - Account with Institution
49/// - **Usage**: Account identification with associated financial institution
50/// - **Components**: Account identifier + Institution BIC code
51/// - **Purpose**: Complete account specification including servicing institution
52/// - **BIC Format**: Standard 8 or 11 character BIC code
53///
54/// ## Business Context
55/// - **Payment Processing**: Essential for routing payments to correct accounts
56/// - **Security Framework**: Enables secure authorization between parties
57/// - **Account Services**: Facilitates account-based financial services
58/// - **Cross-Border Payments**: Provides institution identification for international transfers
59///
60/// ## Authorization Security
61/// - **Digital Signatures**: Electronic signature verification codes
62/// - **Token Authentication**: Security tokens generated by electronic devices
63/// - **Bilateral Agreements**: Institution-specific authorization mechanisms
64/// - **Fraud Prevention**: Additional security layer for payment authorization
65///
66/// ## Examples
67/// ```logic
68/// :25:AUTH123456789 // Authorization code (NoOption)
69/// :25A:/GB82WEST12345698765432 // IBAN account identifier
70/// :25A:/1234567890 // Simple account number
71/// :25P:CHF1234567890 // Account with BIC
72/// UBSWCHZH80XX // Swiss bank BIC
73/// ```
74///
75/// ## Regional Considerations
76/// - **European Payments**: IBAN format compliance for SEPA transactions
77/// - **US Payments**: Federal routing number integration
78/// - **Asian Markets**: Local account numbering standards
79/// - **Cross-Border**: International account identification requirements
80///
81/// ## Account Format Standards
82/// - **IBAN**: International Bank Account Number for European markets
83/// - **BBAN**: Basic Bank Account Number for domestic transactions
84/// - **Local Formats**: Region-specific account numbering schemes
85/// - **Institution Standards**: Bank-specific account identification rules
86///
87/// ## Error Prevention
88/// - **Account Validation**: Verify account exists and is accessible
89/// - **BIC Verification**: Confirm BIC is valid and active
90/// - **Format Checking**: Ensure account format matches regional standards
91/// - **Authorization Validation**: Verify security codes are current and valid
92///
93/// ## Related Fields
94/// - **Field 50**: Ordering Customer (account holder identification)
95/// - **Field 57**: Account With Institution (receiving account details)
96/// - **Field 59**: Beneficiary Customer (final account recipient)
97/// - **Field 52**: Ordering Institution (account servicing institution)
98///
99/// ## Security Considerations
100/// - **Token Management**: Secure generation and validation of authorization tokens
101/// - **Code Expiry**: Time-limited validity of authorization codes
102/// - **Bilateral Security**: Institution-specific security arrangements
103/// - **Audit Trail**: Comprehensive logging of authorization attempts
104///
105/// ## STP Compliance
106/// - **Format Standardization**: Consistent account format for automated processing
107/// - **Validation Enhancement**: Enhanced security validation for STP transactions
108/// - **Exception Handling**: Automated handling of authorization failures
109/// - **Quality Control**: Real-time validation of account and authorization data
110///
111/// ## Compliance and Audit
112/// - **Regulatory Requirements**: Meeting account identification regulations
113/// - **Security Documentation**: Maintaining records of authorization methods
114/// - **Access Control**: Ensuring proper account access authorization
115/// - **Investigation Support**: Authorization tracking for compliance investigations
116///
117/// ## See Also
118/// - Swift FIN User Handbook: Account Identification Standards
119/// - Authorization Guidelines: Security Code Requirements
120/// - IBAN Standards: International Account Number Specifications
121/// - BIC Directory: Institution Identifier Validation
122///
123/// **Field 25 NoOption: Authorisation**
124///
125/// Security authorization code or digital signature between ordering customer
126/// and account servicing financial institution.
127#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
128pub struct Field25NoOption {
129 /// Authorization code or digital signature
130 ///
131 /// Format: 35x - Security token, electronic signature, or agreed authorization code
132 /// Used for additional security verification between customer and institution
133 #[component("35x")]
134 pub authorisation: String,
135}
136
137/// **Field 25A: Account Identifier**
138///
139/// Simple account identification with slash prefix for basic account specification.
140#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
141pub struct Field25A {
142 /// Account identifier with slash prefix
143 ///
144 /// Format: /34x - Account number preceded by slash
145 /// Supports IBAN, BBAN, or institution-specific account formats
146 #[component("/34x")]
147 pub account: String,
148}
149
150/// **Field 25P: Account with Institution**
151///
152/// Account identification with associated financial institution BIC code
153/// for complete account specification.
154#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
155pub struct Field25P {
156 /// Account identifier
157 ///
158 /// Format: 35x - Account number or identifier
159 /// Combined with BIC for complete account specification
160 #[component("35x")]
161 pub account: String,
162
163 /// Bank Identifier Code of account servicing institution
164 ///
165 /// Format: 4!a2!a2!c\[3!c\] - 8 or 11 character BIC code
166 /// Must be valid registered financial institution identifier
167 #[component("4!a2!a2!c[3!c]")]
168 pub bic: String,
169}
170
171/// **Field 25 Account Identification Enum**
172///
173/// Enumeration of account identification options providing flexibility
174/// for different account specification needs.
175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
176pub enum Field25AccountIdentification {
177 /// Authorization code without account specification
178 NoOption(Field25NoOption),
179 /// Account with institution BIC code
180 P(Field25P),
181}