1use crate::parse_result::{ErrorCollector, ParserConfig};
20use crate::validation::{Validate, helpers};
21use serde::{Deserialize, Serialize};
22
23#[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#[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#[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#[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#[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#[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#[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}