mx_message/document/
camt_057_001_06.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
19
20use crate::error::*;
21use regex::Regex;
22use serde::{Deserialize, Serialize};
23
24// AccountIdentification4Choice1: Unique identification of an account, as assigned by the account servicer, using an identification scheme.
25#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
26pub struct AccountIdentification4Choice1 {
27    #[serde(rename = "IBAN", skip_serializing_if = "Option::is_none")]
28    pub iban: Option<String>,
29    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
30    pub othr: Option<GenericAccountIdentification11>,
31}
32
33impl AccountIdentification4Choice1 {
34    pub fn validate(&self) -> Result<(), ValidationError> {
35        if let Some(ref val) = self.iban {
36            let pattern = Regex::new("[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}").unwrap();
37            if !pattern.is_match(val) {
38                return Err(ValidationError::new(
39                    1005,
40                    "iban does not match the required pattern".to_string(),
41                ));
42            }
43        }
44        if let Some(ref val) = self.othr {
45            val.validate()?
46        }
47        Ok(())
48    }
49}
50
51// AccountNotification161: Provides details of the expected amount on the account serviced by the account servicer.
52#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
53pub struct AccountNotification161 {
54    #[serde(rename = "Id")]
55    pub id: String,
56    #[serde(rename = "Acct", skip_serializing_if = "Option::is_none")]
57    pub acct: Option<CashAccount381>,
58    #[serde(rename = "AcctOwnr", skip_serializing_if = "Option::is_none")]
59    pub acct_ownr: Option<Party40Choice2>,
60    #[serde(rename = "AcctSvcr", skip_serializing_if = "Option::is_none")]
61    pub acct_svcr: Option<BranchAndFinancialInstitutionIdentification61>,
62    #[serde(rename = "RltdAcct", skip_serializing_if = "Option::is_none")]
63    pub rltd_acct: Option<CashAccount381>,
64    #[serde(rename = "TtlAmt", skip_serializing_if = "Option::is_none")]
65    pub ttl_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
66    #[serde(rename = "XpctdValDt", skip_serializing_if = "Option::is_none")]
67    pub xpctd_val_dt: Option<String>,
68    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
69    pub dbtr: Option<Party40Choice2>,
70    #[serde(rename = "DbtrAgt", skip_serializing_if = "Option::is_none")]
71    pub dbtr_agt: Option<BranchAndFinancialInstitutionIdentification61>,
72    #[serde(rename = "IntrmyAgt", skip_serializing_if = "Option::is_none")]
73    pub intrmy_agt: Option<BranchAndFinancialInstitutionIdentification61>,
74    #[serde(rename = "Itm")]
75    pub itm: Vec<NotificationItem71>,
76}
77
78impl AccountNotification161 {
79    pub fn validate(&self) -> Result<(), ValidationError> {
80        if self.id.chars().count() < 1 {
81            return Err(ValidationError::new(
82                1001,
83                "id is shorter than the minimum length of 1".to_string(),
84            ));
85        }
86        if self.id.chars().count() > 35 {
87            return Err(ValidationError::new(
88                1002,
89                "id exceeds the maximum length of 35".to_string(),
90            ));
91        }
92        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
93        if !pattern.is_match(&self.id) {
94            return Err(ValidationError::new(
95                1005,
96                "id does not match the required pattern".to_string(),
97            ));
98        }
99        if let Some(ref val) = self.acct {
100            val.validate()?
101        }
102        if let Some(ref val) = self.acct_ownr {
103            val.validate()?
104        }
105        if let Some(ref val) = self.acct_svcr {
106            val.validate()?
107        }
108        if let Some(ref val) = self.rltd_acct {
109            val.validate()?
110        }
111        if let Some(ref val) = self.ttl_amt {
112            val.validate()?
113        }
114        if let Some(ref val) = self.dbtr {
115            val.validate()?
116        }
117        if let Some(ref val) = self.dbtr_agt {
118            val.validate()?
119        }
120        if let Some(ref val) = self.intrmy_agt {
121            val.validate()?
122        }
123        for item in &self.itm {
124            item.validate()?
125        }
126        Ok(())
127    }
128}
129
130// AccountSchemeName1Choice1: Name of the identification scheme, in a free text form.
131#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
132pub struct AccountSchemeName1Choice1 {
133    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
134    pub cd: Option<String>,
135    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
136    pub prtry: Option<String>,
137}
138
139impl AccountSchemeName1Choice1 {
140    pub fn validate(&self) -> Result<(), ValidationError> {
141        if let Some(ref val) = self.cd {
142            if val.chars().count() < 1 {
143                return Err(ValidationError::new(
144                    1001,
145                    "cd is shorter than the minimum length of 1".to_string(),
146                ));
147            }
148            if val.chars().count() > 4 {
149                return Err(ValidationError::new(
150                    1002,
151                    "cd exceeds the maximum length of 4".to_string(),
152                ));
153            }
154        }
155        if let Some(ref val) = self.prtry {
156            if val.chars().count() < 1 {
157                return Err(ValidationError::new(
158                    1001,
159                    "prtry is shorter than the minimum length of 1".to_string(),
160                ));
161            }
162            if val.chars().count() > 35 {
163                return Err(ValidationError::new(
164                    1002,
165                    "prtry exceeds the maximum length of 35".to_string(),
166                ));
167            }
168            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
169            if !pattern.is_match(val) {
170                return Err(ValidationError::new(
171                    1005,
172                    "prtry does not match the required pattern".to_string(),
173                ));
174            }
175        }
176        Ok(())
177    }
178}
179
180// ActiveOrHistoricCurrencyAndAmount: A number of monetary units specified in an active or a historic currency where the unit of currency is explicit and compliant with ISO 4217.
181#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
182pub struct ActiveOrHistoricCurrencyAndAmount {
183    #[serde(rename = "@Ccy")]
184    pub ccy: String,
185    #[serde(rename = "$value")]
186    pub value: f64,
187}
188
189impl ActiveOrHistoricCurrencyAndAmount {
190    pub fn validate(&self) -> Result<(), ValidationError> {
191        Ok(())
192    }
193}
194
195// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
196#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
197pub struct BranchAndFinancialInstitutionIdentification61 {
198    #[serde(rename = "FinInstnId")]
199    pub fin_instn_id: FinancialInstitutionIdentification181,
200}
201
202impl BranchAndFinancialInstitutionIdentification61 {
203    pub fn validate(&self) -> Result<(), ValidationError> {
204        self.fin_instn_id.validate()?;
205        Ok(())
206    }
207}
208
209// CashAccount381: Specifies an alternate assumed name for the identification of the account.
210#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
211pub struct CashAccount381 {
212    #[serde(rename = "Id")]
213    pub id: AccountIdentification4Choice1,
214    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
215    pub tp: Option<CashAccountType2Choice1>,
216    #[serde(rename = "Ccy", skip_serializing_if = "Option::is_none")]
217    pub ccy: Option<String>,
218    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
219    pub nm: Option<String>,
220    #[serde(rename = "Prxy", skip_serializing_if = "Option::is_none")]
221    pub prxy: Option<ProxyAccountIdentification11>,
222}
223
224impl CashAccount381 {
225    pub fn validate(&self) -> Result<(), ValidationError> {
226        self.id.validate()?;
227        if let Some(ref val) = self.tp {
228            val.validate()?
229        }
230        if let Some(ref val) = self.ccy {
231            let pattern = Regex::new("[A-Z]{3,3}").unwrap();
232            if !pattern.is_match(val) {
233                return Err(ValidationError::new(
234                    1005,
235                    "ccy does not match the required pattern".to_string(),
236                ));
237            }
238        }
239        if let Some(ref val) = self.nm {
240            if val.chars().count() < 1 {
241                return Err(ValidationError::new(
242                    1001,
243                    "nm is shorter than the minimum length of 1".to_string(),
244                ));
245            }
246            if val.chars().count() > 70 {
247                return Err(ValidationError::new(
248                    1002,
249                    "nm exceeds the maximum length of 70".to_string(),
250                ));
251            }
252            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
253            if !pattern.is_match(val) {
254                return Err(ValidationError::new(
255                    1005,
256                    "nm does not match the required pattern".to_string(),
257                ));
258            }
259        }
260        if let Some(ref val) = self.prxy {
261            val.validate()?
262        }
263        Ok(())
264    }
265}
266
267// CashAccountType2Choice1: Nature or use of the account in a proprietary form.
268#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
269pub struct CashAccountType2Choice1 {
270    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
271    pub cd: Option<String>,
272    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
273    pub prtry: Option<String>,
274}
275
276impl CashAccountType2Choice1 {
277    pub fn validate(&self) -> Result<(), ValidationError> {
278        if let Some(ref val) = self.cd {
279            if val.chars().count() < 1 {
280                return Err(ValidationError::new(
281                    1001,
282                    "cd is shorter than the minimum length of 1".to_string(),
283                ));
284            }
285            if val.chars().count() > 4 {
286                return Err(ValidationError::new(
287                    1002,
288                    "cd exceeds the maximum length of 4".to_string(),
289                ));
290            }
291        }
292        if let Some(ref val) = self.prtry {
293            if val.chars().count() < 1 {
294                return Err(ValidationError::new(
295                    1001,
296                    "prtry is shorter than the minimum length of 1".to_string(),
297                ));
298            }
299            if val.chars().count() > 35 {
300                return Err(ValidationError::new(
301                    1002,
302                    "prtry exceeds the maximum length of 35".to_string(),
303                ));
304            }
305            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
306            if !pattern.is_match(val) {
307                return Err(ValidationError::new(
308                    1005,
309                    "prtry does not match the required pattern".to_string(),
310                ));
311            }
312        }
313        Ok(())
314    }
315}
316
317// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
318#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
319pub struct ClearingSystemIdentification2Choice1 {
320    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
321    pub cd: Option<String>,
322}
323
324impl ClearingSystemIdentification2Choice1 {
325    pub fn validate(&self) -> Result<(), ValidationError> {
326        if let Some(ref val) = self.cd {
327            if val.chars().count() < 1 {
328                return Err(ValidationError::new(
329                    1001,
330                    "cd is shorter than the minimum length of 1".to_string(),
331                ));
332            }
333            if val.chars().count() > 5 {
334                return Err(ValidationError::new(
335                    1002,
336                    "cd exceeds the maximum length of 5".to_string(),
337                ));
338            }
339        }
340        Ok(())
341    }
342}
343
344// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
345#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
346pub struct ClearingSystemMemberIdentification21 {
347    #[serde(rename = "ClrSysId")]
348    pub clr_sys_id: ClearingSystemIdentification2Choice1,
349    #[serde(rename = "MmbId")]
350    pub mmb_id: String,
351}
352
353impl ClearingSystemMemberIdentification21 {
354    pub fn validate(&self) -> Result<(), ValidationError> {
355        self.clr_sys_id.validate()?;
356        if self.mmb_id.chars().count() < 1 {
357            return Err(ValidationError::new(
358                1001,
359                "mmb_id is shorter than the minimum length of 1".to_string(),
360            ));
361        }
362        if self.mmb_id.chars().count() > 28 {
363            return Err(ValidationError::new(
364                1002,
365                "mmb_id exceeds the maximum length of 28".to_string(),
366            ));
367        }
368        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
369        if !pattern.is_match(&self.mmb_id) {
370            return Err(ValidationError::new(
371                1005,
372                "mmb_id does not match the required pattern".to_string(),
373            ));
374        }
375        Ok(())
376    }
377}
378
379// DateAndPlaceOfBirth1: Country where a person was born.
380#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
381pub struct DateAndPlaceOfBirth1 {
382    #[serde(rename = "BirthDt")]
383    pub birth_dt: String,
384    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
385    pub prvc_of_birth: Option<String>,
386    #[serde(rename = "CityOfBirth")]
387    pub city_of_birth: String,
388    #[serde(rename = "CtryOfBirth")]
389    pub ctry_of_birth: String,
390}
391
392impl DateAndPlaceOfBirth1 {
393    pub fn validate(&self) -> Result<(), ValidationError> {
394        if let Some(ref val) = self.prvc_of_birth {
395            if val.chars().count() < 1 {
396                return Err(ValidationError::new(
397                    1001,
398                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
399                ));
400            }
401            if val.chars().count() > 35 {
402                return Err(ValidationError::new(
403                    1002,
404                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
405                ));
406            }
407        }
408        if self.city_of_birth.chars().count() < 1 {
409            return Err(ValidationError::new(
410                1001,
411                "city_of_birth is shorter than the minimum length of 1".to_string(),
412            ));
413        }
414        if self.city_of_birth.chars().count() > 35 {
415            return Err(ValidationError::new(
416                1002,
417                "city_of_birth exceeds the maximum length of 35".to_string(),
418            ));
419        }
420        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
421        if !pattern.is_match(&self.ctry_of_birth) {
422            return Err(ValidationError::new(
423                1005,
424                "ctry_of_birth does not match the required pattern".to_string(),
425            ));
426        }
427        Ok(())
428    }
429}
430
431// DateAndPlaceOfBirth11: Country where a person was born.
432#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
433pub struct DateAndPlaceOfBirth11 {
434    #[serde(rename = "BirthDt")]
435    pub birth_dt: String,
436    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
437    pub prvc_of_birth: Option<String>,
438    #[serde(rename = "CityOfBirth")]
439    pub city_of_birth: String,
440    #[serde(rename = "CtryOfBirth")]
441    pub ctry_of_birth: String,
442}
443
444impl DateAndPlaceOfBirth11 {
445    pub fn validate(&self) -> Result<(), ValidationError> {
446        if let Some(ref val) = self.prvc_of_birth {
447            if val.chars().count() < 1 {
448                return Err(ValidationError::new(
449                    1001,
450                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
451                ));
452            }
453            if val.chars().count() > 35 {
454                return Err(ValidationError::new(
455                    1002,
456                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
457                ));
458            }
459            let pattern = Regex::new(
460                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
461            )
462            .unwrap();
463            if !pattern.is_match(val) {
464                return Err(ValidationError::new(
465                    1005,
466                    "prvc_of_birth does not match the required pattern".to_string(),
467                ));
468            }
469        }
470        if self.city_of_birth.chars().count() < 1 {
471            return Err(ValidationError::new(
472                1001,
473                "city_of_birth is shorter than the minimum length of 1".to_string(),
474            ));
475        }
476        if self.city_of_birth.chars().count() > 35 {
477            return Err(ValidationError::new(
478                1002,
479                "city_of_birth exceeds the maximum length of 35".to_string(),
480            ));
481        }
482        let pattern =
483            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
484                .unwrap();
485        if !pattern.is_match(&self.city_of_birth) {
486            return Err(ValidationError::new(
487                1005,
488                "city_of_birth does not match the required pattern".to_string(),
489            ));
490        }
491        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
492        if !pattern.is_match(&self.ctry_of_birth) {
493            return Err(ValidationError::new(
494                1005,
495                "ctry_of_birth does not match the required pattern".to_string(),
496            ));
497        }
498        Ok(())
499    }
500}
501
502// FinancialInstitutionIdentification181: Information that locates and identifies a specific address, as defined by postal services.
503#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
504pub struct FinancialInstitutionIdentification181 {
505    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
506    pub bicfi: Option<String>,
507    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
508    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
509    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
510    pub lei: Option<String>,
511    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
512    pub nm: Option<String>,
513    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
514    pub pstl_adr: Option<PostalAddress241>,
515}
516
517impl FinancialInstitutionIdentification181 {
518    pub fn validate(&self) -> Result<(), ValidationError> {
519        if let Some(ref val) = self.bicfi {
520            let pattern =
521                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
522            if !pattern.is_match(val) {
523                return Err(ValidationError::new(
524                    1005,
525                    "bicfi does not match the required pattern".to_string(),
526                ));
527            }
528        }
529        if let Some(ref val) = self.clr_sys_mmb_id {
530            val.validate()?
531        }
532        if let Some(ref val) = self.lei {
533            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
534            if !pattern.is_match(val) {
535                return Err(ValidationError::new(
536                    1005,
537                    "lei does not match the required pattern".to_string(),
538                ));
539            }
540        }
541        if let Some(ref val) = self.nm {
542            if val.chars().count() < 1 {
543                return Err(ValidationError::new(
544                    1001,
545                    "nm is shorter than the minimum length of 1".to_string(),
546                ));
547            }
548            if val.chars().count() > 140 {
549                return Err(ValidationError::new(
550                    1002,
551                    "nm exceeds the maximum length of 140".to_string(),
552                ));
553            }
554            let pattern = Regex::new(
555                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
556            )
557            .unwrap();
558            if !pattern.is_match(val) {
559                return Err(ValidationError::new(
560                    1005,
561                    "nm does not match the required pattern".to_string(),
562                ));
563            }
564        }
565        if let Some(ref val) = self.pstl_adr {
566            val.validate()?
567        }
568        Ok(())
569    }
570}
571
572// GenericAccountIdentification11: Entity that assigns the identification.
573#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
574pub struct GenericAccountIdentification11 {
575    #[serde(rename = "Id")]
576    pub id: String,
577    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
578    pub schme_nm: Option<AccountSchemeName1Choice1>,
579    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
580    pub issr: Option<String>,
581}
582
583impl GenericAccountIdentification11 {
584    pub fn validate(&self) -> Result<(), ValidationError> {
585        if self.id.chars().count() < 1 {
586            return Err(ValidationError::new(
587                1001,
588                "id is shorter than the minimum length of 1".to_string(),
589            ));
590        }
591        if self.id.chars().count() > 34 {
592            return Err(ValidationError::new(
593                1002,
594                "id exceeds the maximum length of 34".to_string(),
595            ));
596        }
597        let pattern = Regex::new("([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]*(/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ])?)*)").unwrap();
598        if !pattern.is_match(&self.id) {
599            return Err(ValidationError::new(
600                1005,
601                "id does not match the required pattern".to_string(),
602            ));
603        }
604        if let Some(ref val) = self.schme_nm {
605            val.validate()?
606        }
607        if let Some(ref val) = self.issr {
608            if val.chars().count() < 1 {
609                return Err(ValidationError::new(
610                    1001,
611                    "issr is shorter than the minimum length of 1".to_string(),
612                ));
613            }
614            if val.chars().count() > 35 {
615                return Err(ValidationError::new(
616                    1002,
617                    "issr exceeds the maximum length of 35".to_string(),
618                ));
619            }
620            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
621            if !pattern.is_match(val) {
622                return Err(ValidationError::new(
623                    1005,
624                    "issr does not match the required pattern".to_string(),
625                ));
626            }
627        }
628        Ok(())
629    }
630}
631
632// GenericOrganisationIdentification11: Entity that assigns the identification.
633#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
634pub struct GenericOrganisationIdentification11 {
635    #[serde(rename = "Id")]
636    pub id: String,
637    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
638    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice1>,
639    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
640    pub issr: Option<String>,
641}
642
643impl GenericOrganisationIdentification11 {
644    pub fn validate(&self) -> Result<(), ValidationError> {
645        if self.id.chars().count() < 1 {
646            return Err(ValidationError::new(
647                1001,
648                "id is shorter than the minimum length of 1".to_string(),
649            ));
650        }
651        if self.id.chars().count() > 35 {
652            return Err(ValidationError::new(
653                1002,
654                "id exceeds the maximum length of 35".to_string(),
655            ));
656        }
657        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
658        if !pattern.is_match(&self.id) {
659            return Err(ValidationError::new(
660                1005,
661                "id does not match the required pattern".to_string(),
662            ));
663        }
664        if let Some(ref val) = self.schme_nm {
665            val.validate()?
666        }
667        if let Some(ref val) = self.issr {
668            if val.chars().count() < 1 {
669                return Err(ValidationError::new(
670                    1001,
671                    "issr is shorter than the minimum length of 1".to_string(),
672                ));
673            }
674            if val.chars().count() > 35 {
675                return Err(ValidationError::new(
676                    1002,
677                    "issr exceeds the maximum length of 35".to_string(),
678                ));
679            }
680            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
681            if !pattern.is_match(val) {
682                return Err(ValidationError::new(
683                    1005,
684                    "issr does not match the required pattern".to_string(),
685                ));
686            }
687        }
688        Ok(())
689    }
690}
691
692// GenericOrganisationIdentification12: Entity that assigns the identification.
693#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
694pub struct GenericOrganisationIdentification12 {
695    #[serde(rename = "Id")]
696    pub id: String,
697    #[serde(rename = "SchmeNm")]
698    pub schme_nm: OrganisationIdentificationSchemeName1Choice2,
699    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
700    pub issr: Option<String>,
701}
702
703impl GenericOrganisationIdentification12 {
704    pub fn validate(&self) -> Result<(), ValidationError> {
705        if self.id.chars().count() < 1 {
706            return Err(ValidationError::new(
707                1001,
708                "id is shorter than the minimum length of 1".to_string(),
709            ));
710        }
711        if self.id.chars().count() > 35 {
712            return Err(ValidationError::new(
713                1002,
714                "id exceeds the maximum length of 35".to_string(),
715            ));
716        }
717        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
718        if !pattern.is_match(&self.id) {
719            return Err(ValidationError::new(
720                1005,
721                "id does not match the required pattern".to_string(),
722            ));
723        }
724        self.schme_nm.validate()?;
725        if let Some(ref val) = self.issr {
726            if val.chars().count() < 1 {
727                return Err(ValidationError::new(
728                    1001,
729                    "issr is shorter than the minimum length of 1".to_string(),
730                ));
731            }
732            if val.chars().count() > 35 {
733                return Err(ValidationError::new(
734                    1002,
735                    "issr exceeds the maximum length of 35".to_string(),
736                ));
737            }
738            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
739            if !pattern.is_match(val) {
740                return Err(ValidationError::new(
741                    1005,
742                    "issr does not match the required pattern".to_string(),
743                ));
744            }
745        }
746        Ok(())
747    }
748}
749
750// GenericPersonIdentification11: Entity that assigns the identification.
751#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
752pub struct GenericPersonIdentification11 {
753    #[serde(rename = "Id")]
754    pub id: String,
755    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
756    pub schme_nm: Option<PersonIdentificationSchemeName1Choice1>,
757    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
758    pub issr: Option<String>,
759}
760
761impl GenericPersonIdentification11 {
762    pub fn validate(&self) -> Result<(), ValidationError> {
763        if self.id.chars().count() < 1 {
764            return Err(ValidationError::new(
765                1001,
766                "id is shorter than the minimum length of 1".to_string(),
767            ));
768        }
769        if self.id.chars().count() > 35 {
770            return Err(ValidationError::new(
771                1002,
772                "id exceeds the maximum length of 35".to_string(),
773            ));
774        }
775        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
776        if !pattern.is_match(&self.id) {
777            return Err(ValidationError::new(
778                1005,
779                "id does not match the required pattern".to_string(),
780            ));
781        }
782        if let Some(ref val) = self.schme_nm {
783            val.validate()?
784        }
785        if let Some(ref val) = self.issr {
786            if val.chars().count() < 1 {
787                return Err(ValidationError::new(
788                    1001,
789                    "issr is shorter than the minimum length of 1".to_string(),
790                ));
791            }
792            if val.chars().count() > 35 {
793                return Err(ValidationError::new(
794                    1002,
795                    "issr exceeds the maximum length of 35".to_string(),
796                ));
797            }
798            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
799            if !pattern.is_match(val) {
800                return Err(ValidationError::new(
801                    1005,
802                    "issr does not match the required pattern".to_string(),
803                ));
804            }
805        }
806        Ok(())
807    }
808}
809
810// GenericPersonIdentification12: Entity that assigns the identification.
811#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
812pub struct GenericPersonIdentification12 {
813    #[serde(rename = "Id")]
814    pub id: String,
815    #[serde(rename = "SchmeNm")]
816    pub schme_nm: PersonIdentificationSchemeName1Choice2,
817    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
818    pub issr: Option<String>,
819}
820
821impl GenericPersonIdentification12 {
822    pub fn validate(&self) -> Result<(), ValidationError> {
823        if self.id.chars().count() < 1 {
824            return Err(ValidationError::new(
825                1001,
826                "id is shorter than the minimum length of 1".to_string(),
827            ));
828        }
829        if self.id.chars().count() > 35 {
830            return Err(ValidationError::new(
831                1002,
832                "id exceeds the maximum length of 35".to_string(),
833            ));
834        }
835        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
836        if !pattern.is_match(&self.id) {
837            return Err(ValidationError::new(
838                1005,
839                "id does not match the required pattern".to_string(),
840            ));
841        }
842        self.schme_nm.validate()?;
843        if let Some(ref val) = self.issr {
844            if val.chars().count() < 1 {
845                return Err(ValidationError::new(
846                    1001,
847                    "issr is shorter than the minimum length of 1".to_string(),
848                ));
849            }
850            if val.chars().count() > 35 {
851                return Err(ValidationError::new(
852                    1002,
853                    "issr exceeds the maximum length of 35".to_string(),
854                ));
855            }
856            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
857            if !pattern.is_match(val) {
858                return Err(ValidationError::new(
859                    1005,
860                    "issr does not match the required pattern".to_string(),
861                ));
862            }
863        }
864        Ok(())
865    }
866}
867
868// GroupHeader771: Identification of the party that is sending the message, when different from the account owner.
869#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
870pub struct GroupHeader771 {
871    #[serde(rename = "MsgId")]
872    pub msg_id: String,
873    #[serde(rename = "CreDtTm")]
874    pub cre_dt_tm: String,
875    #[serde(rename = "MsgSndr", skip_serializing_if = "Option::is_none")]
876    pub msg_sndr: Option<Party40Choice1>,
877}
878
879impl GroupHeader771 {
880    pub fn validate(&self) -> Result<(), ValidationError> {
881        if self.msg_id.chars().count() < 1 {
882            return Err(ValidationError::new(
883                1001,
884                "msg_id is shorter than the minimum length of 1".to_string(),
885            ));
886        }
887        if self.msg_id.chars().count() > 35 {
888            return Err(ValidationError::new(
889                1002,
890                "msg_id exceeds the maximum length of 35".to_string(),
891            ));
892        }
893        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
894        if !pattern.is_match(&self.msg_id) {
895            return Err(ValidationError::new(
896                1005,
897                "msg_id does not match the required pattern".to_string(),
898            ));
899        }
900        let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
901        if !pattern.is_match(&self.cre_dt_tm) {
902            return Err(ValidationError::new(
903                1005,
904                "cre_dt_tm does not match the required pattern".to_string(),
905            ));
906        }
907        if let Some(ref val) = self.msg_sndr {
908            val.validate()?
909        }
910        Ok(())
911    }
912}
913
914// NotificationItem71: Underlying reason for the payment transaction.
915#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
916pub struct NotificationItem71 {
917    #[serde(rename = "Id")]
918    pub id: String,
919    #[serde(rename = "EndToEndId", skip_serializing_if = "Option::is_none")]
920    pub end_to_end_id: Option<String>,
921    #[serde(rename = "UETR", skip_serializing_if = "Option::is_none")]
922    pub uetr: Option<String>,
923    #[serde(rename = "RltdAcct", skip_serializing_if = "Option::is_none")]
924    pub rltd_acct: Option<CashAccount381>,
925    #[serde(rename = "Amt")]
926    pub amt: ActiveOrHistoricCurrencyAndAmount,
927    #[serde(rename = "XpctdValDt", skip_serializing_if = "Option::is_none")]
928    pub xpctd_val_dt: Option<String>,
929    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
930    pub dbtr: Option<Party40Choice3>,
931    #[serde(rename = "DbtrAgt", skip_serializing_if = "Option::is_none")]
932    pub dbtr_agt: Option<BranchAndFinancialInstitutionIdentification61>,
933    #[serde(rename = "IntrmyAgt", skip_serializing_if = "Option::is_none")]
934    pub intrmy_agt: Option<BranchAndFinancialInstitutionIdentification61>,
935    #[serde(rename = "Purp", skip_serializing_if = "Option::is_none")]
936    pub purp: Option<Purpose2Choice1>,
937}
938
939impl NotificationItem71 {
940    pub fn validate(&self) -> Result<(), ValidationError> {
941        if self.id.chars().count() < 1 {
942            return Err(ValidationError::new(
943                1001,
944                "id is shorter than the minimum length of 1".to_string(),
945            ));
946        }
947        if self.id.chars().count() > 35 {
948            return Err(ValidationError::new(
949                1002,
950                "id exceeds the maximum length of 35".to_string(),
951            ));
952        }
953        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
954        if !pattern.is_match(&self.id) {
955            return Err(ValidationError::new(
956                1005,
957                "id does not match the required pattern".to_string(),
958            ));
959        }
960        if let Some(ref val) = self.end_to_end_id {
961            if val.chars().count() < 1 {
962                return Err(ValidationError::new(
963                    1001,
964                    "end_to_end_id is shorter than the minimum length of 1".to_string(),
965                ));
966            }
967            if val.chars().count() > 35 {
968                return Err(ValidationError::new(
969                    1002,
970                    "end_to_end_id exceeds the maximum length of 35".to_string(),
971                ));
972            }
973            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
974            if !pattern.is_match(val) {
975                return Err(ValidationError::new(
976                    1005,
977                    "end_to_end_id does not match the required pattern".to_string(),
978                ));
979            }
980        }
981        if let Some(ref val) = self.uetr {
982            let pattern =
983                Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
984                    .unwrap();
985            if !pattern.is_match(val) {
986                return Err(ValidationError::new(
987                    1005,
988                    "uetr does not match the required pattern".to_string(),
989                ));
990            }
991        }
992        if let Some(ref val) = self.rltd_acct {
993            val.validate()?
994        }
995        self.amt.validate()?;
996        if let Some(ref val) = self.dbtr {
997            val.validate()?
998        }
999        if let Some(ref val) = self.dbtr_agt {
1000            val.validate()?
1001        }
1002        if let Some(ref val) = self.intrmy_agt {
1003            val.validate()?
1004        }
1005        if let Some(ref val) = self.purp {
1006            val.validate()?
1007        }
1008        Ok(())
1009    }
1010}
1011
1012// NotificationToReceiveV06: Set of elements used to provide further details on the account notification.
1013#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1014pub struct NotificationToReceiveV06 {
1015    #[serde(rename = "GrpHdr")]
1016    pub grp_hdr: GroupHeader771,
1017    #[serde(rename = "Ntfctn")]
1018    pub ntfctn: AccountNotification161,
1019}
1020
1021impl NotificationToReceiveV06 {
1022    pub fn validate(&self) -> Result<(), ValidationError> {
1023        self.grp_hdr.validate()?;
1024        self.ntfctn.validate()?;
1025        Ok(())
1026    }
1027}
1028
1029// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
1030#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1031pub struct OrganisationIdentification291 {
1032    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
1033    pub any_bic: Option<String>,
1034    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1035    pub lei: Option<String>,
1036    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1037    pub othr: Option<Vec<GenericOrganisationIdentification11>>,
1038}
1039
1040impl OrganisationIdentification291 {
1041    pub fn validate(&self) -> Result<(), ValidationError> {
1042        if let Some(ref val) = self.any_bic {
1043            let pattern =
1044                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1045            if !pattern.is_match(val) {
1046                return Err(ValidationError::new(
1047                    1005,
1048                    "any_bic does not match the required pattern".to_string(),
1049                ));
1050            }
1051        }
1052        if let Some(ref val) = self.lei {
1053            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1054            if !pattern.is_match(val) {
1055                return Err(ValidationError::new(
1056                    1005,
1057                    "lei does not match the required pattern".to_string(),
1058                ));
1059            }
1060        }
1061        if let Some(ref vec) = self.othr {
1062            for item in vec {
1063                item.validate()?
1064            }
1065        }
1066        Ok(())
1067    }
1068}
1069
1070// OrganisationIdentification292: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
1071#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1072pub struct OrganisationIdentification292 {
1073    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
1074    pub any_bic: Option<String>,
1075    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1076    pub lei: Option<String>,
1077    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1078    pub othr: Option<Vec<GenericOrganisationIdentification12>>,
1079}
1080
1081impl OrganisationIdentification292 {
1082    pub fn validate(&self) -> Result<(), ValidationError> {
1083        if let Some(ref val) = self.any_bic {
1084            let pattern =
1085                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1086            if !pattern.is_match(val) {
1087                return Err(ValidationError::new(
1088                    1005,
1089                    "any_bic does not match the required pattern".to_string(),
1090                ));
1091            }
1092        }
1093        if let Some(ref val) = self.lei {
1094            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1095            if !pattern.is_match(val) {
1096                return Err(ValidationError::new(
1097                    1005,
1098                    "lei does not match the required pattern".to_string(),
1099                ));
1100            }
1101        }
1102        if let Some(ref vec) = self.othr {
1103            for item in vec {
1104                item.validate()?
1105            }
1106        }
1107        Ok(())
1108    }
1109}
1110
1111// OrganisationIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
1112#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1113pub struct OrganisationIdentificationSchemeName1Choice1 {
1114    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1115    pub cd: Option<String>,
1116    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1117    pub prtry: Option<String>,
1118}
1119
1120impl OrganisationIdentificationSchemeName1Choice1 {
1121    pub fn validate(&self) -> Result<(), ValidationError> {
1122        if let Some(ref val) = self.cd {
1123            if val.chars().count() < 1 {
1124                return Err(ValidationError::new(
1125                    1001,
1126                    "cd is shorter than the minimum length of 1".to_string(),
1127                ));
1128            }
1129            if val.chars().count() > 4 {
1130                return Err(ValidationError::new(
1131                    1002,
1132                    "cd exceeds the maximum length of 4".to_string(),
1133                ));
1134            }
1135        }
1136        if let Some(ref val) = self.prtry {
1137            if val.chars().count() < 1 {
1138                return Err(ValidationError::new(
1139                    1001,
1140                    "prtry is shorter than the minimum length of 1".to_string(),
1141                ));
1142            }
1143            if val.chars().count() > 35 {
1144                return Err(ValidationError::new(
1145                    1002,
1146                    "prtry exceeds the maximum length of 35".to_string(),
1147                ));
1148            }
1149            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1150            if !pattern.is_match(val) {
1151                return Err(ValidationError::new(
1152                    1005,
1153                    "prtry does not match the required pattern".to_string(),
1154                ));
1155            }
1156        }
1157        Ok(())
1158    }
1159}
1160
1161// OrganisationIdentificationSchemeName1Choice2: Name of the identification scheme, in a coded form as published in an external list.
1162#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1163pub struct OrganisationIdentificationSchemeName1Choice2 {
1164    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1165    pub cd: Option<String>,
1166}
1167
1168impl OrganisationIdentificationSchemeName1Choice2 {
1169    pub fn validate(&self) -> Result<(), ValidationError> {
1170        if let Some(ref val) = self.cd {
1171            if val.chars().count() < 1 {
1172                return Err(ValidationError::new(
1173                    1001,
1174                    "cd is shorter than the minimum length of 1".to_string(),
1175                ));
1176            }
1177            if val.chars().count() > 4 {
1178                return Err(ValidationError::new(
1179                    1002,
1180                    "cd exceeds the maximum length of 4".to_string(),
1181                ));
1182            }
1183        }
1184        Ok(())
1185    }
1186}
1187
1188// Party38Choice1: Unique and unambiguous identification of a person, for example a passport.
1189#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1190pub struct Party38Choice1 {
1191    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1192    pub org_id: Option<OrganisationIdentification291>,
1193    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1194    pub prvt_id: Option<PersonIdentification131>,
1195}
1196
1197impl Party38Choice1 {
1198    pub fn validate(&self) -> Result<(), ValidationError> {
1199        if let Some(ref val) = self.org_id {
1200            val.validate()?
1201        }
1202        if let Some(ref val) = self.prvt_id {
1203            val.validate()?
1204        }
1205        Ok(())
1206    }
1207}
1208
1209// Party38Choice2: Unique and unambiguous identification of a person, for example a passport.
1210#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1211pub struct Party38Choice2 {
1212    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1213    pub org_id: Option<OrganisationIdentification291>,
1214    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1215    pub prvt_id: Option<PersonIdentification132>,
1216}
1217
1218impl Party38Choice2 {
1219    pub fn validate(&self) -> Result<(), ValidationError> {
1220        if let Some(ref val) = self.org_id {
1221            val.validate()?
1222        }
1223        if let Some(ref val) = self.prvt_id {
1224            val.validate()?
1225        }
1226        Ok(())
1227    }
1228}
1229
1230// Party38Choice3: Unique and unambiguous identification of a person, for example a passport.
1231#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1232pub struct Party38Choice3 {
1233    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1234    pub org_id: Option<OrganisationIdentification292>,
1235    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1236    pub prvt_id: Option<PersonIdentification133>,
1237}
1238
1239impl Party38Choice3 {
1240    pub fn validate(&self) -> Result<(), ValidationError> {
1241        if let Some(ref val) = self.org_id {
1242            val.validate()?
1243        }
1244        if let Some(ref val) = self.prvt_id {
1245            val.validate()?
1246        }
1247        Ok(())
1248    }
1249}
1250
1251// Party40Choice1: Identification of a financial institution.
1252#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1253pub struct Party40Choice1 {
1254    #[serde(rename = "Pty", skip_serializing_if = "Option::is_none")]
1255    pub pty: Option<PartyIdentification1351>,
1256    #[serde(rename = "Agt", skip_serializing_if = "Option::is_none")]
1257    pub agt: Option<BranchAndFinancialInstitutionIdentification61>,
1258}
1259
1260impl Party40Choice1 {
1261    pub fn validate(&self) -> Result<(), ValidationError> {
1262        if let Some(ref val) = self.pty {
1263            val.validate()?
1264        }
1265        if let Some(ref val) = self.agt {
1266            val.validate()?
1267        }
1268        Ok(())
1269    }
1270}
1271
1272// Party40Choice2: Identification of a financial institution.
1273#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1274pub struct Party40Choice2 {
1275    #[serde(rename = "Pty", skip_serializing_if = "Option::is_none")]
1276    pub pty: Option<PartyIdentification1352>,
1277    #[serde(rename = "Agt", skip_serializing_if = "Option::is_none")]
1278    pub agt: Option<BranchAndFinancialInstitutionIdentification61>,
1279}
1280
1281impl Party40Choice2 {
1282    pub fn validate(&self) -> Result<(), ValidationError> {
1283        if let Some(ref val) = self.pty {
1284            val.validate()?
1285        }
1286        if let Some(ref val) = self.agt {
1287            val.validate()?
1288        }
1289        Ok(())
1290    }
1291}
1292
1293// Party40Choice3: Identification of a financial institution.
1294#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1295pub struct Party40Choice3 {
1296    #[serde(rename = "Pty", skip_serializing_if = "Option::is_none")]
1297    pub pty: Option<PartyIdentification1353>,
1298    #[serde(rename = "Agt", skip_serializing_if = "Option::is_none")]
1299    pub agt: Option<BranchAndFinancialInstitutionIdentification61>,
1300}
1301
1302impl Party40Choice3 {
1303    pub fn validate(&self) -> Result<(), ValidationError> {
1304        if let Some(ref val) = self.pty {
1305            val.validate()?
1306        }
1307        if let Some(ref val) = self.agt {
1308            val.validate()?
1309        }
1310        Ok(())
1311    }
1312}
1313
1314// PartyIdentification1351: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
1315#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1316pub struct PartyIdentification1351 {
1317    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1318    pub nm: Option<String>,
1319    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1320    pub pstl_adr: Option<PostalAddress241>,
1321    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1322    pub id: Option<Party38Choice1>,
1323    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1324    pub ctry_of_res: Option<String>,
1325}
1326
1327impl PartyIdentification1351 {
1328    pub fn validate(&self) -> Result<(), ValidationError> {
1329        if let Some(ref val) = self.nm {
1330            if val.chars().count() < 1 {
1331                return Err(ValidationError::new(
1332                    1001,
1333                    "nm is shorter than the minimum length of 1".to_string(),
1334                ));
1335            }
1336            if val.chars().count() > 140 {
1337                return Err(ValidationError::new(
1338                    1002,
1339                    "nm exceeds the maximum length of 140".to_string(),
1340                ));
1341            }
1342            let pattern = Regex::new(
1343                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1344            )
1345            .unwrap();
1346            if !pattern.is_match(val) {
1347                return Err(ValidationError::new(
1348                    1005,
1349                    "nm does not match the required pattern".to_string(),
1350                ));
1351            }
1352        }
1353        if let Some(ref val) = self.pstl_adr {
1354            val.validate()?
1355        }
1356        if let Some(ref val) = self.id {
1357            val.validate()?
1358        }
1359        if let Some(ref val) = self.ctry_of_res {
1360            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1361            if !pattern.is_match(val) {
1362                return Err(ValidationError::new(
1363                    1005,
1364                    "ctry_of_res does not match the required pattern".to_string(),
1365                ));
1366            }
1367        }
1368        Ok(())
1369    }
1370}
1371
1372// PartyIdentification1352: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
1373#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1374pub struct PartyIdentification1352 {
1375    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1376    pub nm: Option<String>,
1377    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1378    pub pstl_adr: Option<PostalAddress241>,
1379    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1380    pub id: Option<Party38Choice2>,
1381    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1382    pub ctry_of_res: Option<String>,
1383}
1384
1385impl PartyIdentification1352 {
1386    pub fn validate(&self) -> Result<(), ValidationError> {
1387        if let Some(ref val) = self.nm {
1388            if val.chars().count() < 1 {
1389                return Err(ValidationError::new(
1390                    1001,
1391                    "nm is shorter than the minimum length of 1".to_string(),
1392                ));
1393            }
1394            if val.chars().count() > 140 {
1395                return Err(ValidationError::new(
1396                    1002,
1397                    "nm exceeds the maximum length of 140".to_string(),
1398                ));
1399            }
1400            let pattern = Regex::new(
1401                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1402            )
1403            .unwrap();
1404            if !pattern.is_match(val) {
1405                return Err(ValidationError::new(
1406                    1005,
1407                    "nm does not match the required pattern".to_string(),
1408                ));
1409            }
1410        }
1411        if let Some(ref val) = self.pstl_adr {
1412            val.validate()?
1413        }
1414        if let Some(ref val) = self.id {
1415            val.validate()?
1416        }
1417        if let Some(ref val) = self.ctry_of_res {
1418            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1419            if !pattern.is_match(val) {
1420                return Err(ValidationError::new(
1421                    1005,
1422                    "ctry_of_res does not match the required pattern".to_string(),
1423                ));
1424            }
1425        }
1426        Ok(())
1427    }
1428}
1429
1430// PartyIdentification1353: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
1431#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1432pub struct PartyIdentification1353 {
1433    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1434    pub nm: Option<String>,
1435    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1436    pub pstl_adr: Option<PostalAddress241>,
1437    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1438    pub id: Option<Party38Choice3>,
1439    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1440    pub ctry_of_res: Option<String>,
1441}
1442
1443impl PartyIdentification1353 {
1444    pub fn validate(&self) -> Result<(), ValidationError> {
1445        if let Some(ref val) = self.nm {
1446            if val.chars().count() < 1 {
1447                return Err(ValidationError::new(
1448                    1001,
1449                    "nm is shorter than the minimum length of 1".to_string(),
1450                ));
1451            }
1452            if val.chars().count() > 140 {
1453                return Err(ValidationError::new(
1454                    1002,
1455                    "nm exceeds the maximum length of 140".to_string(),
1456                ));
1457            }
1458            let pattern = Regex::new(
1459                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1460            )
1461            .unwrap();
1462            if !pattern.is_match(val) {
1463                return Err(ValidationError::new(
1464                    1005,
1465                    "nm does not match the required pattern".to_string(),
1466                ));
1467            }
1468        }
1469        if let Some(ref val) = self.pstl_adr {
1470            val.validate()?
1471        }
1472        if let Some(ref val) = self.id {
1473            val.validate()?
1474        }
1475        if let Some(ref val) = self.ctry_of_res {
1476            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1477            if !pattern.is_match(val) {
1478                return Err(ValidationError::new(
1479                    1005,
1480                    "ctry_of_res does not match the required pattern".to_string(),
1481                ));
1482            }
1483        }
1484        Ok(())
1485    }
1486}
1487
1488// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
1489#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1490pub struct PersonIdentification131 {
1491    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1492    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
1493    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1494    pub othr: Option<Vec<GenericPersonIdentification11>>,
1495}
1496
1497impl PersonIdentification131 {
1498    pub fn validate(&self) -> Result<(), ValidationError> {
1499        if let Some(ref val) = self.dt_and_plc_of_birth {
1500            val.validate()?
1501        }
1502        if let Some(ref vec) = self.othr {
1503            for item in vec {
1504                item.validate()?
1505            }
1506        }
1507        Ok(())
1508    }
1509}
1510
1511// PersonIdentification132: Unique identification of a person, as assigned by an institution, using an identification scheme.
1512#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1513pub struct PersonIdentification132 {
1514    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1515    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth1>,
1516    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1517    pub othr: Option<Vec<GenericPersonIdentification11>>,
1518}
1519
1520impl PersonIdentification132 {
1521    pub fn validate(&self) -> Result<(), ValidationError> {
1522        if let Some(ref val) = self.dt_and_plc_of_birth {
1523            val.validate()?
1524        }
1525        if let Some(ref vec) = self.othr {
1526            for item in vec {
1527                item.validate()?
1528            }
1529        }
1530        Ok(())
1531    }
1532}
1533
1534// PersonIdentification133: Unique identification of a person, as assigned by an institution, using an identification scheme.
1535#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1536pub struct PersonIdentification133 {
1537    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1538    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
1539    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1540    pub othr: Option<Vec<GenericPersonIdentification12>>,
1541}
1542
1543impl PersonIdentification133 {
1544    pub fn validate(&self) -> Result<(), ValidationError> {
1545        if let Some(ref val) = self.dt_and_plc_of_birth {
1546            val.validate()?
1547        }
1548        if let Some(ref vec) = self.othr {
1549            for item in vec {
1550                item.validate()?
1551            }
1552        }
1553        Ok(())
1554    }
1555}
1556
1557// PersonIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
1558#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1559pub struct PersonIdentificationSchemeName1Choice1 {
1560    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1561    pub cd: Option<String>,
1562    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1563    pub prtry: Option<String>,
1564}
1565
1566impl PersonIdentificationSchemeName1Choice1 {
1567    pub fn validate(&self) -> Result<(), ValidationError> {
1568        if let Some(ref val) = self.cd {
1569            if val.chars().count() < 1 {
1570                return Err(ValidationError::new(
1571                    1001,
1572                    "cd is shorter than the minimum length of 1".to_string(),
1573                ));
1574            }
1575            if val.chars().count() > 4 {
1576                return Err(ValidationError::new(
1577                    1002,
1578                    "cd exceeds the maximum length of 4".to_string(),
1579                ));
1580            }
1581        }
1582        if let Some(ref val) = self.prtry {
1583            if val.chars().count() < 1 {
1584                return Err(ValidationError::new(
1585                    1001,
1586                    "prtry is shorter than the minimum length of 1".to_string(),
1587                ));
1588            }
1589            if val.chars().count() > 35 {
1590                return Err(ValidationError::new(
1591                    1002,
1592                    "prtry exceeds the maximum length of 35".to_string(),
1593                ));
1594            }
1595            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1596            if !pattern.is_match(val) {
1597                return Err(ValidationError::new(
1598                    1005,
1599                    "prtry does not match the required pattern".to_string(),
1600                ));
1601            }
1602        }
1603        Ok(())
1604    }
1605}
1606
1607// PersonIdentificationSchemeName1Choice2: Name of the identification scheme, in a coded form as published in an external list.
1608#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1609pub struct PersonIdentificationSchemeName1Choice2 {
1610    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1611    pub cd: Option<String>,
1612}
1613
1614impl PersonIdentificationSchemeName1Choice2 {
1615    pub fn validate(&self) -> Result<(), ValidationError> {
1616        if let Some(ref val) = self.cd {
1617            if val.chars().count() < 1 {
1618                return Err(ValidationError::new(
1619                    1001,
1620                    "cd is shorter than the minimum length of 1".to_string(),
1621                ));
1622            }
1623            if val.chars().count() > 4 {
1624                return Err(ValidationError::new(
1625                    1002,
1626                    "cd exceeds the maximum length of 4".to_string(),
1627                ));
1628            }
1629        }
1630        Ok(())
1631    }
1632}
1633
1634// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
1635#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1636pub struct PostalAddress241 {
1637    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
1638    pub dept: Option<String>,
1639    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
1640    pub sub_dept: Option<String>,
1641    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
1642    pub strt_nm: Option<String>,
1643    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
1644    pub bldg_nb: Option<String>,
1645    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
1646    pub bldg_nm: Option<String>,
1647    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
1648    pub flr: Option<String>,
1649    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
1650    pub pst_bx: Option<String>,
1651    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
1652    pub room: Option<String>,
1653    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
1654    pub pst_cd: Option<String>,
1655    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
1656    pub twn_nm: Option<String>,
1657    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
1658    pub twn_lctn_nm: Option<String>,
1659    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
1660    pub dstrct_nm: Option<String>,
1661    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
1662    pub ctry_sub_dvsn: Option<String>,
1663    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
1664    pub ctry: Option<String>,
1665    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
1666    pub adr_line: Option<Vec<String>>,
1667}
1668
1669impl PostalAddress241 {
1670    pub fn validate(&self) -> Result<(), ValidationError> {
1671        if let Some(ref val) = self.dept {
1672            if val.chars().count() < 1 {
1673                return Err(ValidationError::new(
1674                    1001,
1675                    "dept is shorter than the minimum length of 1".to_string(),
1676                ));
1677            }
1678            if val.chars().count() > 70 {
1679                return Err(ValidationError::new(
1680                    1002,
1681                    "dept exceeds the maximum length of 70".to_string(),
1682                ));
1683            }
1684            let pattern = Regex::new(
1685                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1686            )
1687            .unwrap();
1688            if !pattern.is_match(val) {
1689                return Err(ValidationError::new(
1690                    1005,
1691                    "dept does not match the required pattern".to_string(),
1692                ));
1693            }
1694        }
1695        if let Some(ref val) = self.sub_dept {
1696            if val.chars().count() < 1 {
1697                return Err(ValidationError::new(
1698                    1001,
1699                    "sub_dept is shorter than the minimum length of 1".to_string(),
1700                ));
1701            }
1702            if val.chars().count() > 70 {
1703                return Err(ValidationError::new(
1704                    1002,
1705                    "sub_dept exceeds the maximum length of 70".to_string(),
1706                ));
1707            }
1708            let pattern = Regex::new(
1709                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1710            )
1711            .unwrap();
1712            if !pattern.is_match(val) {
1713                return Err(ValidationError::new(
1714                    1005,
1715                    "sub_dept does not match the required pattern".to_string(),
1716                ));
1717            }
1718        }
1719        if let Some(ref val) = self.strt_nm {
1720            if val.chars().count() < 1 {
1721                return Err(ValidationError::new(
1722                    1001,
1723                    "strt_nm is shorter than the minimum length of 1".to_string(),
1724                ));
1725            }
1726            if val.chars().count() > 70 {
1727                return Err(ValidationError::new(
1728                    1002,
1729                    "strt_nm exceeds the maximum length of 70".to_string(),
1730                ));
1731            }
1732            let pattern = Regex::new(
1733                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1734            )
1735            .unwrap();
1736            if !pattern.is_match(val) {
1737                return Err(ValidationError::new(
1738                    1005,
1739                    "strt_nm does not match the required pattern".to_string(),
1740                ));
1741            }
1742        }
1743        if let Some(ref val) = self.bldg_nb {
1744            if val.chars().count() < 1 {
1745                return Err(ValidationError::new(
1746                    1001,
1747                    "bldg_nb is shorter than the minimum length of 1".to_string(),
1748                ));
1749            }
1750            if val.chars().count() > 16 {
1751                return Err(ValidationError::new(
1752                    1002,
1753                    "bldg_nb exceeds the maximum length of 16".to_string(),
1754                ));
1755            }
1756            let pattern = Regex::new(
1757                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1758            )
1759            .unwrap();
1760            if !pattern.is_match(val) {
1761                return Err(ValidationError::new(
1762                    1005,
1763                    "bldg_nb does not match the required pattern".to_string(),
1764                ));
1765            }
1766        }
1767        if let Some(ref val) = self.bldg_nm {
1768            if val.chars().count() < 1 {
1769                return Err(ValidationError::new(
1770                    1001,
1771                    "bldg_nm is shorter than the minimum length of 1".to_string(),
1772                ));
1773            }
1774            if val.chars().count() > 35 {
1775                return Err(ValidationError::new(
1776                    1002,
1777                    "bldg_nm exceeds the maximum length of 35".to_string(),
1778                ));
1779            }
1780            let pattern = Regex::new(
1781                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1782            )
1783            .unwrap();
1784            if !pattern.is_match(val) {
1785                return Err(ValidationError::new(
1786                    1005,
1787                    "bldg_nm does not match the required pattern".to_string(),
1788                ));
1789            }
1790        }
1791        if let Some(ref val) = self.flr {
1792            if val.chars().count() < 1 {
1793                return Err(ValidationError::new(
1794                    1001,
1795                    "flr is shorter than the minimum length of 1".to_string(),
1796                ));
1797            }
1798            if val.chars().count() > 70 {
1799                return Err(ValidationError::new(
1800                    1002,
1801                    "flr exceeds the maximum length of 70".to_string(),
1802                ));
1803            }
1804            let pattern = Regex::new(
1805                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1806            )
1807            .unwrap();
1808            if !pattern.is_match(val) {
1809                return Err(ValidationError::new(
1810                    1005,
1811                    "flr does not match the required pattern".to_string(),
1812                ));
1813            }
1814        }
1815        if let Some(ref val) = self.pst_bx {
1816            if val.chars().count() < 1 {
1817                return Err(ValidationError::new(
1818                    1001,
1819                    "pst_bx is shorter than the minimum length of 1".to_string(),
1820                ));
1821            }
1822            if val.chars().count() > 16 {
1823                return Err(ValidationError::new(
1824                    1002,
1825                    "pst_bx exceeds the maximum length of 16".to_string(),
1826                ));
1827            }
1828            let pattern = Regex::new(
1829                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1830            )
1831            .unwrap();
1832            if !pattern.is_match(val) {
1833                return Err(ValidationError::new(
1834                    1005,
1835                    "pst_bx does not match the required pattern".to_string(),
1836                ));
1837            }
1838        }
1839        if let Some(ref val) = self.room {
1840            if val.chars().count() < 1 {
1841                return Err(ValidationError::new(
1842                    1001,
1843                    "room is shorter than the minimum length of 1".to_string(),
1844                ));
1845            }
1846            if val.chars().count() > 70 {
1847                return Err(ValidationError::new(
1848                    1002,
1849                    "room exceeds the maximum length of 70".to_string(),
1850                ));
1851            }
1852            let pattern = Regex::new(
1853                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1854            )
1855            .unwrap();
1856            if !pattern.is_match(val) {
1857                return Err(ValidationError::new(
1858                    1005,
1859                    "room does not match the required pattern".to_string(),
1860                ));
1861            }
1862        }
1863        if let Some(ref val) = self.pst_cd {
1864            if val.chars().count() < 1 {
1865                return Err(ValidationError::new(
1866                    1001,
1867                    "pst_cd is shorter than the minimum length of 1".to_string(),
1868                ));
1869            }
1870            if val.chars().count() > 16 {
1871                return Err(ValidationError::new(
1872                    1002,
1873                    "pst_cd exceeds the maximum length of 16".to_string(),
1874                ));
1875            }
1876            let pattern = Regex::new(
1877                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1878            )
1879            .unwrap();
1880            if !pattern.is_match(val) {
1881                return Err(ValidationError::new(
1882                    1005,
1883                    "pst_cd does not match the required pattern".to_string(),
1884                ));
1885            }
1886        }
1887        if let Some(ref val) = self.twn_nm {
1888            if val.chars().count() < 1 {
1889                return Err(ValidationError::new(
1890                    1001,
1891                    "twn_nm is shorter than the minimum length of 1".to_string(),
1892                ));
1893            }
1894            if val.chars().count() > 35 {
1895                return Err(ValidationError::new(
1896                    1002,
1897                    "twn_nm exceeds the maximum length of 35".to_string(),
1898                ));
1899            }
1900            let pattern = Regex::new(
1901                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1902            )
1903            .unwrap();
1904            if !pattern.is_match(val) {
1905                return Err(ValidationError::new(
1906                    1005,
1907                    "twn_nm does not match the required pattern".to_string(),
1908                ));
1909            }
1910        }
1911        if let Some(ref val) = self.twn_lctn_nm {
1912            if val.chars().count() < 1 {
1913                return Err(ValidationError::new(
1914                    1001,
1915                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
1916                ));
1917            }
1918            if val.chars().count() > 35 {
1919                return Err(ValidationError::new(
1920                    1002,
1921                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
1922                ));
1923            }
1924            let pattern = Regex::new(
1925                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1926            )
1927            .unwrap();
1928            if !pattern.is_match(val) {
1929                return Err(ValidationError::new(
1930                    1005,
1931                    "twn_lctn_nm does not match the required pattern".to_string(),
1932                ));
1933            }
1934        }
1935        if let Some(ref val) = self.dstrct_nm {
1936            if val.chars().count() < 1 {
1937                return Err(ValidationError::new(
1938                    1001,
1939                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
1940                ));
1941            }
1942            if val.chars().count() > 35 {
1943                return Err(ValidationError::new(
1944                    1002,
1945                    "dstrct_nm exceeds the maximum length of 35".to_string(),
1946                ));
1947            }
1948            let pattern = Regex::new(
1949                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1950            )
1951            .unwrap();
1952            if !pattern.is_match(val) {
1953                return Err(ValidationError::new(
1954                    1005,
1955                    "dstrct_nm does not match the required pattern".to_string(),
1956                ));
1957            }
1958        }
1959        if let Some(ref val) = self.ctry_sub_dvsn {
1960            if val.chars().count() < 1 {
1961                return Err(ValidationError::new(
1962                    1001,
1963                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
1964                ));
1965            }
1966            if val.chars().count() > 35 {
1967                return Err(ValidationError::new(
1968                    1002,
1969                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
1970                ));
1971            }
1972            let pattern = Regex::new(
1973                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1974            )
1975            .unwrap();
1976            if !pattern.is_match(val) {
1977                return Err(ValidationError::new(
1978                    1005,
1979                    "ctry_sub_dvsn does not match the required pattern".to_string(),
1980                ));
1981            }
1982        }
1983        if let Some(ref val) = self.ctry {
1984            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1985            if !pattern.is_match(val) {
1986                return Err(ValidationError::new(
1987                    1005,
1988                    "ctry does not match the required pattern".to_string(),
1989                ));
1990            }
1991        }
1992        if let Some(ref vec) = self.adr_line {
1993            for item in vec {
1994                if item.chars().count() < 1 {
1995                    return Err(ValidationError::new(
1996                        1001,
1997                        "adr_line is shorter than the minimum length of 1".to_string(),
1998                    ));
1999                }
2000                if item.chars().count() > 70 {
2001                    return Err(ValidationError::new(
2002                        1002,
2003                        "adr_line exceeds the maximum length of 70".to_string(),
2004                    ));
2005                }
2006                let pattern = Regex::new(
2007                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2008                )
2009                .unwrap();
2010                if !pattern.is_match(&item) {
2011                    return Err(ValidationError::new(
2012                        1005,
2013                        "adr_line does not match the required pattern".to_string(),
2014                    ));
2015                }
2016            }
2017        }
2018        Ok(())
2019    }
2020}
2021
2022// ProxyAccountIdentification11: Identification used to indicate the account identification under another specified name.
2023#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2024pub struct ProxyAccountIdentification11 {
2025    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
2026    pub tp: Option<ProxyAccountType1Choice1>,
2027    #[serde(rename = "Id")]
2028    pub id: String,
2029}
2030
2031impl ProxyAccountIdentification11 {
2032    pub fn validate(&self) -> Result<(), ValidationError> {
2033        if let Some(ref val) = self.tp {
2034            val.validate()?
2035        }
2036        if self.id.chars().count() < 1 {
2037            return Err(ValidationError::new(
2038                1001,
2039                "id is shorter than the minimum length of 1".to_string(),
2040            ));
2041        }
2042        if self.id.chars().count() > 320 {
2043            return Err(ValidationError::new(
2044                1002,
2045                "id exceeds the maximum length of 320".to_string(),
2046            ));
2047        }
2048        let pattern =
2049            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
2050                .unwrap();
2051        if !pattern.is_match(&self.id) {
2052            return Err(ValidationError::new(
2053                1005,
2054                "id does not match the required pattern".to_string(),
2055            ));
2056        }
2057        Ok(())
2058    }
2059}
2060
2061// ProxyAccountType1Choice1: Name of the identification scheme, in a free text form.
2062#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2063pub struct ProxyAccountType1Choice1 {
2064    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2065    pub cd: Option<String>,
2066    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2067    pub prtry: Option<String>,
2068}
2069
2070impl ProxyAccountType1Choice1 {
2071    pub fn validate(&self) -> Result<(), ValidationError> {
2072        if let Some(ref val) = self.cd {
2073            if val.chars().count() < 1 {
2074                return Err(ValidationError::new(
2075                    1001,
2076                    "cd is shorter than the minimum length of 1".to_string(),
2077                ));
2078            }
2079            if val.chars().count() > 4 {
2080                return Err(ValidationError::new(
2081                    1002,
2082                    "cd exceeds the maximum length of 4".to_string(),
2083                ));
2084            }
2085        }
2086        if let Some(ref val) = self.prtry {
2087            if val.chars().count() < 1 {
2088                return Err(ValidationError::new(
2089                    1001,
2090                    "prtry is shorter than the minimum length of 1".to_string(),
2091                ));
2092            }
2093            if val.chars().count() > 35 {
2094                return Err(ValidationError::new(
2095                    1002,
2096                    "prtry exceeds the maximum length of 35".to_string(),
2097                ));
2098            }
2099            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
2100            if !pattern.is_match(val) {
2101                return Err(ValidationError::new(
2102                    1005,
2103                    "prtry does not match the required pattern".to_string(),
2104                ));
2105            }
2106        }
2107        Ok(())
2108    }
2109}
2110
2111// Purpose2Choice1: Purpose, in a proprietary form.
2112#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2113pub struct Purpose2Choice1 {
2114    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2115    pub cd: Option<String>,
2116    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2117    pub prtry: Option<String>,
2118}
2119
2120impl Purpose2Choice1 {
2121    pub fn validate(&self) -> Result<(), ValidationError> {
2122        if let Some(ref val) = self.cd {
2123            if val.chars().count() < 1 {
2124                return Err(ValidationError::new(
2125                    1001,
2126                    "cd is shorter than the minimum length of 1".to_string(),
2127                ));
2128            }
2129            if val.chars().count() > 4 {
2130                return Err(ValidationError::new(
2131                    1002,
2132                    "cd exceeds the maximum length of 4".to_string(),
2133                ));
2134            }
2135        }
2136        if let Some(ref val) = self.prtry {
2137            if val.chars().count() < 1 {
2138                return Err(ValidationError::new(
2139                    1001,
2140                    "prtry is shorter than the minimum length of 1".to_string(),
2141                ));
2142            }
2143            if val.chars().count() > 35 {
2144                return Err(ValidationError::new(
2145                    1002,
2146                    "prtry exceeds the maximum length of 35".to_string(),
2147                ));
2148            }
2149            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
2150            if !pattern.is_match(val) {
2151                return Err(ValidationError::new(
2152                    1005,
2153                    "prtry does not match the required pattern".to_string(),
2154                ));
2155            }
2156        }
2157        Ok(())
2158    }
2159}