swift_mt_message/messages/
mt910.rs

1use crate::fields::*;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// # MT910: Confirmation of Credit
6///
7/// This message is used by a financial institution to confirm to another financial institution
8/// that a credit has been made to the sender's account held with the receiver, or that
9/// the sender's account held with a third party has been credited. This message serves
10/// as official confirmation of credit transactions and facilitates reconciliation between
11/// financial institutions.
12///
13/// ## Key Features
14/// - **Credit confirmation**: Official confirmation of credit transactions
15/// - **Account reconciliation**: Facilitates reconciliation between institutions
16/// - **Audit trail**: Creates audit records for credit transactions
17/// - **Settlement confirmation**: Confirms settlement credits
18/// - **Liquidity management**: Account balance change notifications
19///
20/// ## Field Structure
21/// All fields follow the enhanced macro system with proper validation rules.
22/// The message supports both customer and institutional originator identification.
23///
24/// ## Conditional Rules
25/// - **C1**: Either Field 50a or Field 52a must be present (not both)
26#[serde_swift_fields]
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
28#[validation_rules(MT910_VALIDATION_RULES)]
29pub struct MT910 {
30    /// **Transaction Reference Number** - Field 20
31    ///
32    /// Unique sender's reference identifying this specific credit confirmation.
33    /// Used throughout the confirmation lifecycle for tracking, reconciliation, and audit.
34    /// Must be unique within the sender's system per business day.
35    #[field("20", mandatory)]
36    pub field_20: GenericReferenceField,
37
38    /// **Related Reference** - Field 21
39    ///
40    /// Reference to the original transaction or message that resulted in this credit.
41    /// Should be copied unchanged from the original inward MT103/202 that triggered
42    /// this credit confirmation.
43    #[field("21", mandatory)]
44    pub field_21: GenericReferenceField,
45
46    /// **Account Identification** - Field 25a
47    ///
48    /// Identifies the specific account that has been credited. This account
49    /// is typically held by the sender with the receiver, or with a third party
50    /// as specified in the original transaction.
51    #[field("25", mandatory)]
52    pub field_25: GenericTextField,
53
54    /// **Value Date, Currency, Amount** - Field 32A
55    ///
56    /// Core credit details specifying when the credit was effective, in what currency,
57    /// and for what amount. The value date indicates when the credit actually
58    /// took effect on the account.
59    #[field("32A", mandatory)]
60    pub field_32a: Field32A,
61
62    /// **Date/Time Indication** - Field 13D (Optional)
63    ///
64    /// Provides precise timing information for when the credit was processed,
65    /// including UTC offset for accurate time coordination across time zones.
66    #[field("13D", optional)]
67    pub field_13d: Option<Field13D>,
68
69    /// **Ordering Customer** - Field 50a (Conditional C1)
70    ///
71    /// Identifies the customer who originated the transaction that resulted in this credit.
72    /// This field provides customer-level traceability for the credit transaction.
73    #[field("50", optional)]
74    pub field_50a: Option<Field50>,
75
76    /// **Ordering Institution** - Field 52a (Conditional C1)
77    ///
78    /// Identifies the financial institution of the ordering customer or the institution
79    /// that ordered the transaction resulting in this credit. Alternative to Field 50a
80    /// when institutional-level identification is more appropriate.
81    #[field("52", optional)]
82    pub field_52a: Option<GenericBicField>,
83
84    /// **Intermediary** - Field 56a (Optional)
85    ///
86    /// Identifies the financial institution from which the sender received the funds
87    /// that resulted in this credit. Used to document the routing chain and source
88    /// of funds for audit and reconciliation purposes.
89    #[field("56", optional)]
90    pub field_56a: Option<GenericBicField>,
91
92    /// **Sender to Receiver Information** - Field 72 (Optional)
93    ///
94    /// Free-format field for additional information about the credit transaction.
95    /// Must contain narrative information only and may include structured codes
96    /// for bilateral use or exchange rate information.
97    #[field("72", optional)]
98    pub field_72: Option<GenericMultiLineTextField<6, 35>>,
99}
100
101/// Enhanced validation rules for MT910
102const MT910_VALIDATION_RULES: &str = r#"{
103  "rules": [
104    {
105      "id": "C1",
106      "description": "Either Field 50a or Field 52a must be present (not both)",
107      "condition": {
108        "or": [
109          {
110            "and": [
111              {"var": "field_50a.is_some"},
112              {"var": "field_52a.is_none"}
113            ]
114          },
115          {
116            "and": [
117              {"var": "field_50a.is_none"},
118              {"var": "field_52a.is_some"}
119            ]
120          }
121        ]
122      }
123    },
124    {
125      "id": "REF_FORMAT",
126      "description": "Transaction and related references must not have invalid slash patterns",
127      "condition": {
128        "and": [
129          {"!": {"startsWith": [{"var": "field_20.value"}, "/"]}},
130          {"!": {"endsWith": [{"var": "field_20.value"}, "/"]}},
131          {"!": {"includes": [{"var": "field_20.value"}, "//"]}},
132          {"!": {"startsWith": [{"var": "field_21.value"}, "/"]}},
133          {"!": {"endsWith": [{"var": "field_21.value"}, "/"]}},
134          {"!": {"includes": [{"var": "field_21.value"}, "//"]}}
135        ]
136      }
137    },
138    {
139      "id": "AMOUNT_POSITIVE",
140      "description": "Credit amount must be positive",
141      "condition": {
142        ">": [{"var": "field_32a.amount"}, 0]
143      }
144    }
145  ]
146}"#;