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