mx_message/document/
admi_024_001_01.rs

1// Plasmatic MX Message Parsing Library
2// https://github.com/GoPlasmatic/MXMessage
3//
4// Copyright (c) 2025 Plasmatic
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// You may obtain a copy of this library at
18// https://github.com/GoPlasmatic/MXMessage
19use crate::parse_result::{ErrorCollector, ParserConfig};
20use crate::validation::{Validate, helpers};
21use serde::{Deserialize, Serialize};
22
23// BranchAndFinancialInstitutionIdentification81: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
24#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
25pub struct BranchAndFinancialInstitutionIdentification81 {
26    #[serde(rename = "FinInstnId")]
27    pub fin_instn_id: FinancialInstitutionIdentification231,
28}
29
30impl Validate for BranchAndFinancialInstitutionIdentification81 {
31    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
32        self.fin_instn_id
33            .validate(&helpers::child_path(path, "FinInstnId"), config, collector);
34    }
35}
36
37// CorrespondenceNotification11: Provides information about the notification in narrative form.
38#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
39pub struct CorrespondenceNotification11 {
40    #[serde(rename = "SndrNtfctnId")]
41    pub sndr_ntfctn_id: String,
42    #[serde(rename = "NtfctnTp")]
43    pub ntfctn_tp: NotificationType1Choice1,
44    #[serde(rename = "NtfctnNrrtv")]
45    pub ntfctn_nrrtv: Vec<String>,
46}
47
48impl Validate for CorrespondenceNotification11 {
49    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
50        helpers::validate_length(
51            &self.sndr_ntfctn_id,
52            "SndrNtfctnId",
53            Some(1),
54            Some(35),
55            &helpers::child_path(path, "SndrNtfctnId"),
56            config,
57            collector,
58        );
59        helpers::validate_pattern(
60            &self.sndr_ntfctn_id,
61            "SndrNtfctnId",
62            "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+",
63            &helpers::child_path(path, "SndrNtfctnId"),
64            config,
65            collector,
66        );
67        self.ntfctn_tp
68            .validate(&helpers::child_path(path, "NtfctnTp"), config, collector);
69        for item in &self.ntfctn_nrrtv {
70            helpers::validate_length(
71                item,
72                "NtfctnNrrtv",
73                Some(1),
74                Some(2000),
75                &helpers::child_path(path, "NtfctnNrrtv"),
76                config,
77                collector,
78            );
79        }
80        for item in &self.ntfctn_nrrtv {
81            helpers::validate_pattern(
82                item,
83                "NtfctnNrrtv",
84                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
85                &helpers::child_path(path, "NtfctnNrrtv"),
86                config,
87                collector,
88            );
89        }
90    }
91}
92
93// FinancialInstitutionIdentification231: Code allocated to a financial institution by the ISO 9362 Registration Authority as described in ISO 9362 "Banking - Banking telecommunication messages - Business identifier code (BIC)".
94#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
95pub struct FinancialInstitutionIdentification231 {
96    #[serde(rename = "BICFI")]
97    pub bicfi: String,
98}
99
100impl Validate for FinancialInstitutionIdentification231 {
101    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
102        helpers::validate_pattern(
103            &self.bicfi,
104            "BICFI",
105            "[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}",
106            &helpers::child_path(path, "BICFI"),
107            config,
108            collector,
109        );
110    }
111}
112
113// GroupHeader1291: Party that receives the notification.
114#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
115pub struct GroupHeader1291 {
116    #[serde(rename = "MsgId")]
117    pub msg_id: String,
118    #[serde(rename = "CreDtTm")]
119    pub cre_dt_tm: String,
120    #[serde(rename = "Sndr")]
121    pub sndr: Party50Choice1,
122    #[serde(rename = "Rcvr")]
123    pub rcvr: Party50Choice1,
124}
125
126impl Validate for GroupHeader1291 {
127    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
128        helpers::validate_length(
129            &self.msg_id,
130            "MsgId",
131            Some(1),
132            Some(35),
133            &helpers::child_path(path, "MsgId"),
134            config,
135            collector,
136        );
137        helpers::validate_pattern(
138            &self.msg_id,
139            "MsgId",
140            "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+",
141            &helpers::child_path(path, "MsgId"),
142            config,
143            collector,
144        );
145        helpers::validate_pattern(
146            &self.cre_dt_tm,
147            "CreDtTm",
148            ".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]",
149            &helpers::child_path(path, "CreDtTm"),
150            config,
151            collector,
152        );
153        self.sndr
154            .validate(&helpers::child_path(path, "Sndr"), config, collector);
155        self.rcvr
156            .validate(&helpers::child_path(path, "Rcvr"), config, collector);
157    }
158}
159
160// NotificationOfCorrespondenceV01: Set of elements used to provide further details on the notification.
161#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
162pub struct NotificationOfCorrespondenceV01 {
163    #[serde(rename = "GrpHdr")]
164    pub grp_hdr: GroupHeader1291,
165    #[serde(rename = "NtfctnData")]
166    pub ntfctn_data: CorrespondenceNotification11,
167}
168
169impl Validate for NotificationOfCorrespondenceV01 {
170    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
171        self.grp_hdr
172            .validate(&helpers::child_path(path, "GrpHdr"), config, collector);
173        self.ntfctn_data
174            .validate(&helpers::child_path(path, "NtfctnData"), config, collector);
175    }
176}
177
178// NotificationType1Choice1: Notification type, as published in an external notification type code set.
179#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
180pub struct NotificationType1Choice1 {
181    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
182    pub cd: Option<String>,
183}
184
185impl Validate for NotificationType1Choice1 {
186    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
187        if let Some(ref val) = self.cd {
188            helpers::validate_length(
189                val,
190                "Cd",
191                Some(1),
192                Some(4),
193                &helpers::child_path(path, "Cd"),
194                config,
195                collector,
196            );
197        }
198    }
199}
200
201// Party50Choice1: Identification of a financial institution.
202#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
203pub struct Party50Choice1 {
204    #[serde(rename = "Agt", skip_serializing_if = "Option::is_none")]
205    pub agt: Option<BranchAndFinancialInstitutionIdentification81>,
206}
207
208impl Validate for Party50Choice1 {
209    fn validate(&self, path: &str, config: &ParserConfig, collector: &mut ErrorCollector) {
210        if let Some(ref val) = self.agt
211            && config.validate_optional_fields
212        {
213            val.validate(&helpers::child_path(path, "Agt"), config, collector);
214        }
215    }
216}