mx_message/document/
camt_058_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// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
25#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
26pub struct BranchAndFinancialInstitutionIdentification61 {
27    #[serde(rename = "FinInstnId")]
28    pub fin_instn_id: FinancialInstitutionIdentification181,
29}
30
31impl BranchAndFinancialInstitutionIdentification61 {
32    pub fn validate(&self) -> Result<(), ValidationError> {
33        self.fin_instn_id.validate()?;
34        Ok(())
35    }
36}
37
38// CBPRAmount: CBPR_Amount
39#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
40pub struct CBPRAmount {
41    #[serde(rename = "@Ccy")]
42    pub ccy: String,
43    #[serde(rename = "$value")]
44    pub value: f64,
45}
46
47impl CBPRAmount {
48    pub fn validate(&self) -> Result<(), ValidationError> {
49        Ok(())
50    }
51}
52
53// CBPR_NotificationToReceiveCancellationReason1Code: The payment is cancelled since the entry is no longer expected.
54#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
55pub enum CBPRNotificationToReceiveCancellationReason1Code {
56    #[default]
57    #[serde(rename = "DUPL")]
58    CodeDUPL,
59    #[serde(rename = "NARR")]
60    CodeNARR,
61    #[serde(rename = "NOLE")]
62    CodeNOLE,
63}
64
65impl CBPRNotificationToReceiveCancellationReason1Code {
66    pub fn validate(&self) -> Result<(), ValidationError> {
67        Ok(())
68    }
69}
70
71// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
72#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
73pub struct ClearingSystemIdentification2Choice1 {
74    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
75    pub cd: Option<String>,
76}
77
78impl ClearingSystemIdentification2Choice1 {
79    pub fn validate(&self) -> Result<(), ValidationError> {
80        if let Some(ref val) = self.cd {
81            if val.chars().count() < 1 {
82                return Err(ValidationError::new(
83                    1001,
84                    "cd is shorter than the minimum length of 1".to_string(),
85                ));
86            }
87            if val.chars().count() > 5 {
88                return Err(ValidationError::new(
89                    1002,
90                    "cd exceeds the maximum length of 5".to_string(),
91                ));
92            }
93        }
94        Ok(())
95    }
96}
97
98// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
99#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
100pub struct ClearingSystemMemberIdentification21 {
101    #[serde(rename = "ClrSysId")]
102    pub clr_sys_id: ClearingSystemIdentification2Choice1,
103    #[serde(rename = "MmbId")]
104    pub mmb_id: String,
105}
106
107impl ClearingSystemMemberIdentification21 {
108    pub fn validate(&self) -> Result<(), ValidationError> {
109        self.clr_sys_id.validate()?;
110        if self.mmb_id.chars().count() < 1 {
111            return Err(ValidationError::new(
112                1001,
113                "mmb_id is shorter than the minimum length of 1".to_string(),
114            ));
115        }
116        if self.mmb_id.chars().count() > 28 {
117            return Err(ValidationError::new(
118                1002,
119                "mmb_id exceeds the maximum length of 28".to_string(),
120            ));
121        }
122        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
123        if !pattern.is_match(&self.mmb_id) {
124            return Err(ValidationError::new(
125                1005,
126                "mmb_id does not match the required pattern".to_string(),
127            ));
128        }
129        Ok(())
130    }
131}
132
133// DateAndPlaceOfBirth11: Country where a person was born.
134#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
135pub struct DateAndPlaceOfBirth11 {
136    #[serde(rename = "BirthDt")]
137    pub birth_dt: String,
138    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
139    pub prvc_of_birth: Option<String>,
140    #[serde(rename = "CityOfBirth")]
141    pub city_of_birth: String,
142    #[serde(rename = "CtryOfBirth")]
143    pub ctry_of_birth: String,
144}
145
146impl DateAndPlaceOfBirth11 {
147    pub fn validate(&self) -> Result<(), ValidationError> {
148        if let Some(ref val) = self.prvc_of_birth {
149            if val.chars().count() < 1 {
150                return Err(ValidationError::new(
151                    1001,
152                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
153                ));
154            }
155            if val.chars().count() > 35 {
156                return Err(ValidationError::new(
157                    1002,
158                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
159                ));
160            }
161            let pattern = Regex::new(
162                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
163            )
164            .unwrap();
165            if !pattern.is_match(val) {
166                return Err(ValidationError::new(
167                    1005,
168                    "prvc_of_birth does not match the required pattern".to_string(),
169                ));
170            }
171        }
172        if self.city_of_birth.chars().count() < 1 {
173            return Err(ValidationError::new(
174                1001,
175                "city_of_birth is shorter than the minimum length of 1".to_string(),
176            ));
177        }
178        if self.city_of_birth.chars().count() > 35 {
179            return Err(ValidationError::new(
180                1002,
181                "city_of_birth exceeds the maximum length of 35".to_string(),
182            ));
183        }
184        let pattern =
185            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
186                .unwrap();
187        if !pattern.is_match(&self.city_of_birth) {
188            return Err(ValidationError::new(
189                1005,
190                "city_of_birth does not match the required pattern".to_string(),
191            ));
192        }
193        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
194        if !pattern.is_match(&self.ctry_of_birth) {
195            return Err(ValidationError::new(
196                1005,
197                "ctry_of_birth does not match the required pattern".to_string(),
198            ));
199        }
200        Ok(())
201    }
202}
203
204// FinancialInstitutionIdentification181: Information that locates and identifies a specific address, as defined by postal services.
205#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
206pub struct FinancialInstitutionIdentification181 {
207    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
208    pub bicfi: Option<String>,
209    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
210    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
211    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
212    pub lei: Option<String>,
213    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
214    pub nm: Option<String>,
215    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
216    pub pstl_adr: Option<PostalAddress241>,
217}
218
219impl FinancialInstitutionIdentification181 {
220    pub fn validate(&self) -> Result<(), ValidationError> {
221        if let Some(ref val) = self.bicfi {
222            let pattern =
223                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
224            if !pattern.is_match(val) {
225                return Err(ValidationError::new(
226                    1005,
227                    "bicfi does not match the required pattern".to_string(),
228                ));
229            }
230        }
231        if let Some(ref val) = self.clr_sys_mmb_id {
232            val.validate()?
233        }
234        if let Some(ref val) = self.lei {
235            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
236            if !pattern.is_match(val) {
237                return Err(ValidationError::new(
238                    1005,
239                    "lei does not match the required pattern".to_string(),
240                ));
241            }
242        }
243        if let Some(ref val) = self.nm {
244            if val.chars().count() < 1 {
245                return Err(ValidationError::new(
246                    1001,
247                    "nm is shorter than the minimum length of 1".to_string(),
248                ));
249            }
250            if val.chars().count() > 140 {
251                return Err(ValidationError::new(
252                    1002,
253                    "nm exceeds the maximum length of 140".to_string(),
254                ));
255            }
256            let pattern = Regex::new(
257                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
258            )
259            .unwrap();
260            if !pattern.is_match(val) {
261                return Err(ValidationError::new(
262                    1005,
263                    "nm does not match the required pattern".to_string(),
264                ));
265            }
266        }
267        if let Some(ref val) = self.pstl_adr {
268            val.validate()?
269        }
270        Ok(())
271    }
272}
273
274// GenericOrganisationIdentification11: Entity that assigns the identification.
275#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
276pub struct GenericOrganisationIdentification11 {
277    #[serde(rename = "Id")]
278    pub id: String,
279    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
280    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice1>,
281    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
282    pub issr: Option<String>,
283}
284
285impl GenericOrganisationIdentification11 {
286    pub fn validate(&self) -> Result<(), ValidationError> {
287        if self.id.chars().count() < 1 {
288            return Err(ValidationError::new(
289                1001,
290                "id is shorter than the minimum length of 1".to_string(),
291            ));
292        }
293        if self.id.chars().count() > 35 {
294            return Err(ValidationError::new(
295                1002,
296                "id exceeds the maximum length of 35".to_string(),
297            ));
298        }
299        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
300        if !pattern.is_match(&self.id) {
301            return Err(ValidationError::new(
302                1005,
303                "id does not match the required pattern".to_string(),
304            ));
305        }
306        if let Some(ref val) = self.schme_nm {
307            val.validate()?
308        }
309        if let Some(ref val) = self.issr {
310            if val.chars().count() < 1 {
311                return Err(ValidationError::new(
312                    1001,
313                    "issr is shorter than the minimum length of 1".to_string(),
314                ));
315            }
316            if val.chars().count() > 35 {
317                return Err(ValidationError::new(
318                    1002,
319                    "issr exceeds the maximum length of 35".to_string(),
320                ));
321            }
322            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
323            if !pattern.is_match(val) {
324                return Err(ValidationError::new(
325                    1005,
326                    "issr does not match the required pattern".to_string(),
327                ));
328            }
329        }
330        Ok(())
331    }
332}
333
334// GenericPersonIdentification11: Entity that assigns the identification.
335#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
336pub struct GenericPersonIdentification11 {
337    #[serde(rename = "Id")]
338    pub id: String,
339    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
340    pub schme_nm: Option<PersonIdentificationSchemeName1Choice1>,
341    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
342    pub issr: Option<String>,
343}
344
345impl GenericPersonIdentification11 {
346    pub fn validate(&self) -> Result<(), ValidationError> {
347        if self.id.chars().count() < 1 {
348            return Err(ValidationError::new(
349                1001,
350                "id is shorter than the minimum length of 1".to_string(),
351            ));
352        }
353        if self.id.chars().count() > 35 {
354            return Err(ValidationError::new(
355                1002,
356                "id exceeds the maximum length of 35".to_string(),
357            ));
358        }
359        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
360        if !pattern.is_match(&self.id) {
361            return Err(ValidationError::new(
362                1005,
363                "id does not match the required pattern".to_string(),
364            ));
365        }
366        if let Some(ref val) = self.schme_nm {
367            val.validate()?
368        }
369        if let Some(ref val) = self.issr {
370            if val.chars().count() < 1 {
371                return Err(ValidationError::new(
372                    1001,
373                    "issr is shorter than the minimum length of 1".to_string(),
374                ));
375            }
376            if val.chars().count() > 35 {
377                return Err(ValidationError::new(
378                    1002,
379                    "issr exceeds the maximum length of 35".to_string(),
380                ));
381            }
382            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
383            if !pattern.is_match(val) {
384                return Err(ValidationError::new(
385                    1005,
386                    "issr does not match the required pattern".to_string(),
387                ));
388            }
389        }
390        Ok(())
391    }
392}
393
394// GroupHeader771: Identification of the party that is sending the message, when different from the account owner.
395#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
396pub struct GroupHeader771 {
397    #[serde(rename = "MsgId")]
398    pub msg_id: String,
399    #[serde(rename = "CreDtTm")]
400    pub cre_dt_tm: String,
401    #[serde(rename = "MsgSndr", skip_serializing_if = "Option::is_none")]
402    pub msg_sndr: Option<Party40Choice1>,
403}
404
405impl GroupHeader771 {
406    pub fn validate(&self) -> Result<(), ValidationError> {
407        if self.msg_id.chars().count() < 1 {
408            return Err(ValidationError::new(
409                1001,
410                "msg_id is shorter than the minimum length of 1".to_string(),
411            ));
412        }
413        if self.msg_id.chars().count() > 16 {
414            return Err(ValidationError::new(
415                1002,
416                "msg_id exceeds the maximum length of 16".to_string(),
417            ));
418        }
419        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
420        if !pattern.is_match(&self.msg_id) {
421            return Err(ValidationError::new(
422                1005,
423                "msg_id does not match the required pattern".to_string(),
424            ));
425        }
426        let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
427        if !pattern.is_match(&self.cre_dt_tm) {
428            return Err(ValidationError::new(
429                1005,
430                "cre_dt_tm does not match the required pattern".to_string(),
431            ));
432        }
433        if let Some(ref val) = self.msg_sndr {
434            val.validate()?
435        }
436        Ok(())
437    }
438}
439
440// NotificationCancellationReason1Choice1: Reason for the cancellation request, in a coded form.
441#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
442pub struct NotificationCancellationReason1Choice1 {
443    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
444    pub cd: Option<CBPRNotificationToReceiveCancellationReason1Code>,
445}
446
447impl NotificationCancellationReason1Choice1 {
448    pub fn validate(&self) -> Result<(), ValidationError> {
449        if let Some(ref val) = self.cd {
450            val.validate()?
451        }
452        Ok(())
453    }
454}
455
456// NotificationCancellationReason11: Further details on the cancellation request reason.
457#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
458pub struct NotificationCancellationReason11 {
459    #[serde(rename = "Orgtr", skip_serializing_if = "Option::is_none")]
460    pub orgtr: Option<PartyIdentification1351>,
461    #[serde(rename = "Rsn")]
462    pub rsn: NotificationCancellationReason1Choice1,
463    #[serde(rename = "AddtlInf", skip_serializing_if = "Option::is_none")]
464    pub addtl_inf: Option<Vec<String>>,
465}
466
467impl NotificationCancellationReason11 {
468    pub fn validate(&self) -> Result<(), ValidationError> {
469        if let Some(ref val) = self.orgtr {
470            val.validate()?
471        }
472        self.rsn.validate()?;
473        if let Some(ref vec) = self.addtl_inf {
474            for item in vec {
475                if item.chars().count() < 1 {
476                    return Err(ValidationError::new(
477                        1001,
478                        "addtl_inf is shorter than the minimum length of 1".to_string(),
479                    ));
480                }
481                if item.chars().count() > 105 {
482                    return Err(ValidationError::new(
483                        1002,
484                        "addtl_inf exceeds the maximum length of 105".to_string(),
485                    ));
486                }
487                let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
488                if !pattern.is_match(&item) {
489                    return Err(ValidationError::new(
490                        1005,
491                        "addtl_inf does not match the required pattern".to_string(),
492                    ));
493                }
494            }
495        }
496        Ok(())
497    }
498}
499
500// NotificationToReceiveCancellationAdviceV08: Reason for the cancellation of the notification.
501#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
502pub struct NotificationToReceiveCancellationAdviceV08 {
503    #[serde(rename = "GrpHdr")]
504    pub grp_hdr: GroupHeader771,
505    #[serde(rename = "OrgnlNtfctn")]
506    pub orgnl_ntfctn: OriginalNotification141,
507    #[serde(rename = "CxlRsn")]
508    pub cxl_rsn: NotificationCancellationReason11,
509}
510
511impl NotificationToReceiveCancellationAdviceV08 {
512    pub fn validate(&self) -> Result<(), ValidationError> {
513        self.grp_hdr.validate()?;
514        self.orgnl_ntfctn.validate()?;
515        self.cxl_rsn.validate()?;
516        Ok(())
517    }
518}
519
520// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
521#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
522pub struct OrganisationIdentification291 {
523    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
524    pub any_bic: Option<String>,
525    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
526    pub lei: Option<String>,
527    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
528    pub othr: Option<Vec<GenericOrganisationIdentification11>>,
529}
530
531impl OrganisationIdentification291 {
532    pub fn validate(&self) -> Result<(), ValidationError> {
533        if let Some(ref val) = self.any_bic {
534            let pattern =
535                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
536            if !pattern.is_match(val) {
537                return Err(ValidationError::new(
538                    1005,
539                    "any_bic does not match the required pattern".to_string(),
540                ));
541            }
542        }
543        if let Some(ref val) = self.lei {
544            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
545            if !pattern.is_match(val) {
546                return Err(ValidationError::new(
547                    1005,
548                    "lei does not match the required pattern".to_string(),
549                ));
550            }
551        }
552        if let Some(ref vec) = self.othr {
553            for item in vec {
554                item.validate()?
555            }
556        }
557        Ok(())
558    }
559}
560
561// OrganisationIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
562#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
563pub struct OrganisationIdentificationSchemeName1Choice1 {
564    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
565    pub cd: Option<String>,
566    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
567    pub prtry: Option<String>,
568}
569
570impl OrganisationIdentificationSchemeName1Choice1 {
571    pub fn validate(&self) -> Result<(), ValidationError> {
572        if let Some(ref val) = self.cd {
573            if val.chars().count() < 1 {
574                return Err(ValidationError::new(
575                    1001,
576                    "cd is shorter than the minimum length of 1".to_string(),
577                ));
578            }
579            if val.chars().count() > 4 {
580                return Err(ValidationError::new(
581                    1002,
582                    "cd exceeds the maximum length of 4".to_string(),
583                ));
584            }
585        }
586        if let Some(ref val) = self.prtry {
587            if val.chars().count() < 1 {
588                return Err(ValidationError::new(
589                    1001,
590                    "prtry is shorter than the minimum length of 1".to_string(),
591                ));
592            }
593            if val.chars().count() > 35 {
594                return Err(ValidationError::new(
595                    1002,
596                    "prtry exceeds the maximum length of 35".to_string(),
597                ));
598            }
599            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
600            if !pattern.is_match(val) {
601                return Err(ValidationError::new(
602                    1005,
603                    "prtry does not match the required pattern".to_string(),
604                ));
605            }
606        }
607        Ok(())
608    }
609}
610
611// OriginalItem71: Provides further information in order to identify a previous payment notification.
612#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
613pub struct OriginalItem71 {
614    #[serde(rename = "OrgnlItmId")]
615    pub orgnl_itm_id: String,
616    #[serde(rename = "OrgnlEndToEndId", skip_serializing_if = "Option::is_none")]
617    pub orgnl_end_to_end_id: Option<String>,
618    #[serde(rename = "UETR", skip_serializing_if = "Option::is_none")]
619    pub uetr: Option<String>,
620    #[serde(rename = "Amt")]
621    pub amt: CBPRAmount,
622    #[serde(rename = "XpctdValDt", skip_serializing_if = "Option::is_none")]
623    pub xpctd_val_dt: Option<String>,
624    #[serde(rename = "OrgnlItmRef", skip_serializing_if = "Option::is_none")]
625    pub orgnl_itm_ref: Option<OriginalItemReference61>,
626}
627
628impl OriginalItem71 {
629    pub fn validate(&self) -> Result<(), ValidationError> {
630        if self.orgnl_itm_id.chars().count() < 1 {
631            return Err(ValidationError::new(
632                1001,
633                "orgnl_itm_id is shorter than the minimum length of 1".to_string(),
634            ));
635        }
636        if self.orgnl_itm_id.chars().count() > 16 {
637            return Err(ValidationError::new(
638                1002,
639                "orgnl_itm_id exceeds the maximum length of 16".to_string(),
640            ));
641        }
642        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
643        if !pattern.is_match(&self.orgnl_itm_id) {
644            return Err(ValidationError::new(
645                1005,
646                "orgnl_itm_id does not match the required pattern".to_string(),
647            ));
648        }
649        if let Some(ref val) = self.orgnl_end_to_end_id {
650            if val.chars().count() < 1 {
651                return Err(ValidationError::new(
652                    1001,
653                    "orgnl_end_to_end_id is shorter than the minimum length of 1".to_string(),
654                ));
655            }
656            if val.chars().count() > 35 {
657                return Err(ValidationError::new(
658                    1002,
659                    "orgnl_end_to_end_id exceeds the maximum length of 35".to_string(),
660                ));
661            }
662            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
663            if !pattern.is_match(val) {
664                return Err(ValidationError::new(
665                    1005,
666                    "orgnl_end_to_end_id does not match the required pattern".to_string(),
667                ));
668            }
669        }
670        if let Some(ref val) = self.uetr {
671            let pattern =
672                Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
673                    .unwrap();
674            if !pattern.is_match(val) {
675                return Err(ValidationError::new(
676                    1005,
677                    "uetr does not match the required pattern".to_string(),
678                ));
679            }
680        }
681        self.amt.validate()?;
682        if let Some(ref val) = self.orgnl_itm_ref {
683            val.validate()?
684        }
685        Ok(())
686    }
687}
688
689// OriginalItemReference61: Financial institution servicing an account for the debtor.
690#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
691pub struct OriginalItemReference61 {
692    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
693    pub dbtr: Option<Party40Choice1>,
694    #[serde(rename = "DbtrAgt", skip_serializing_if = "Option::is_none")]
695    pub dbtr_agt: Option<BranchAndFinancialInstitutionIdentification61>,
696}
697
698impl OriginalItemReference61 {
699    pub fn validate(&self) -> Result<(), ValidationError> {
700        if let Some(ref val) = self.dbtr {
701            val.validate()?
702        }
703        if let Some(ref val) = self.dbtr_agt {
704            val.validate()?
705        }
706        Ok(())
707    }
708}
709
710// OriginalNotification141: Identifies the original notification item, to which the cancellation advice refers.
711#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
712pub struct OriginalNotification141 {
713    #[serde(rename = "OrgnlMsgId")]
714    pub orgnl_msg_id: String,
715    #[serde(rename = "OrgnlCreDtTm", skip_serializing_if = "Option::is_none")]
716    pub orgnl_cre_dt_tm: Option<String>,
717    #[serde(rename = "OrgnlNtfctnId")]
718    pub orgnl_ntfctn_id: String,
719    #[serde(rename = "OrgnlNtfctnRef")]
720    pub orgnl_ntfctn_ref: OriginalNotificationReference121,
721}
722
723impl OriginalNotification141 {
724    pub fn validate(&self) -> Result<(), ValidationError> {
725        if self.orgnl_msg_id.chars().count() < 1 {
726            return Err(ValidationError::new(
727                1001,
728                "orgnl_msg_id is shorter than the minimum length of 1".to_string(),
729            ));
730        }
731        if self.orgnl_msg_id.chars().count() > 35 {
732            return Err(ValidationError::new(
733                1002,
734                "orgnl_msg_id exceeds the maximum length of 35".to_string(),
735            ));
736        }
737        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
738        if !pattern.is_match(&self.orgnl_msg_id) {
739            return Err(ValidationError::new(
740                1005,
741                "orgnl_msg_id does not match the required pattern".to_string(),
742            ));
743        }
744        if let Some(ref val) = self.orgnl_cre_dt_tm {
745            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
746            if !pattern.is_match(val) {
747                return Err(ValidationError::new(
748                    1005,
749                    "orgnl_cre_dt_tm does not match the required pattern".to_string(),
750                ));
751            }
752        }
753        if self.orgnl_ntfctn_id.chars().count() < 1 {
754            return Err(ValidationError::new(
755                1001,
756                "orgnl_ntfctn_id is shorter than the minimum length of 1".to_string(),
757            ));
758        }
759        if self.orgnl_ntfctn_id.chars().count() > 35 {
760            return Err(ValidationError::new(
761                1002,
762                "orgnl_ntfctn_id exceeds the maximum length of 35".to_string(),
763            ));
764        }
765        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
766        if !pattern.is_match(&self.orgnl_ntfctn_id) {
767            return Err(ValidationError::new(
768                1005,
769                "orgnl_ntfctn_id does not match the required pattern".to_string(),
770            ));
771        }
772        self.orgnl_ntfctn_ref.validate()?;
773        Ok(())
774    }
775}
776
777// OriginalNotificationReference121: Provides details of the expected amount on the account serviced by the account servicer.
778#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
779pub struct OriginalNotificationReference121 {
780    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
781    pub dbtr: Option<Party40Choice1>,
782    #[serde(rename = "DbtrAgt", skip_serializing_if = "Option::is_none")]
783    pub dbtr_agt: Option<BranchAndFinancialInstitutionIdentification61>,
784    #[serde(rename = "OrgnlItm")]
785    pub orgnl_itm: Vec<OriginalItem71>,
786}
787
788impl OriginalNotificationReference121 {
789    pub fn validate(&self) -> Result<(), ValidationError> {
790        if let Some(ref val) = self.dbtr {
791            val.validate()?
792        }
793        if let Some(ref val) = self.dbtr_agt {
794            val.validate()?
795        }
796        for item in &self.orgnl_itm {
797            item.validate()?
798        }
799        Ok(())
800    }
801}
802
803// Party38Choice1: Unique and unambiguous identification of a person, for example a passport.
804#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
805pub struct Party38Choice1 {
806    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
807    pub org_id: Option<OrganisationIdentification291>,
808    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
809    pub prvt_id: Option<PersonIdentification131>,
810}
811
812impl Party38Choice1 {
813    pub fn validate(&self) -> Result<(), ValidationError> {
814        if let Some(ref val) = self.org_id {
815            val.validate()?
816        }
817        if let Some(ref val) = self.prvt_id {
818            val.validate()?
819        }
820        Ok(())
821    }
822}
823
824// Party40Choice1: Identification of a financial institution.
825#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
826pub struct Party40Choice1 {
827    #[serde(rename = "Pty", skip_serializing_if = "Option::is_none")]
828    pub pty: Option<PartyIdentification1351>,
829    #[serde(rename = "Agt", skip_serializing_if = "Option::is_none")]
830    pub agt: Option<BranchAndFinancialInstitutionIdentification61>,
831}
832
833impl Party40Choice1 {
834    pub fn validate(&self) -> Result<(), ValidationError> {
835        if let Some(ref val) = self.pty {
836            val.validate()?
837        }
838        if let Some(ref val) = self.agt {
839            val.validate()?
840        }
841        Ok(())
842    }
843}
844
845// 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.
846#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
847pub struct PartyIdentification1351 {
848    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
849    pub nm: Option<String>,
850    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
851    pub pstl_adr: Option<PostalAddress241>,
852    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
853    pub id: Option<Party38Choice1>,
854    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
855    pub ctry_of_res: Option<String>,
856}
857
858impl PartyIdentification1351 {
859    pub fn validate(&self) -> Result<(), ValidationError> {
860        if let Some(ref val) = self.nm {
861            if val.chars().count() < 1 {
862                return Err(ValidationError::new(
863                    1001,
864                    "nm is shorter than the minimum length of 1".to_string(),
865                ));
866            }
867            if val.chars().count() > 140 {
868                return Err(ValidationError::new(
869                    1002,
870                    "nm exceeds the maximum length of 140".to_string(),
871                ));
872            }
873            let pattern = Regex::new(
874                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
875            )
876            .unwrap();
877            if !pattern.is_match(val) {
878                return Err(ValidationError::new(
879                    1005,
880                    "nm does not match the required pattern".to_string(),
881                ));
882            }
883        }
884        if let Some(ref val) = self.pstl_adr {
885            val.validate()?
886        }
887        if let Some(ref val) = self.id {
888            val.validate()?
889        }
890        if let Some(ref val) = self.ctry_of_res {
891            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
892            if !pattern.is_match(val) {
893                return Err(ValidationError::new(
894                    1005,
895                    "ctry_of_res does not match the required pattern".to_string(),
896                ));
897            }
898        }
899        Ok(())
900    }
901}
902
903// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
904#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
905pub struct PersonIdentification131 {
906    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
907    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
908    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
909    pub othr: Option<Vec<GenericPersonIdentification11>>,
910}
911
912impl PersonIdentification131 {
913    pub fn validate(&self) -> Result<(), ValidationError> {
914        if let Some(ref val) = self.dt_and_plc_of_birth {
915            val.validate()?
916        }
917        if let Some(ref vec) = self.othr {
918            for item in vec {
919                item.validate()?
920            }
921        }
922        Ok(())
923    }
924}
925
926// PersonIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
927#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
928pub struct PersonIdentificationSchemeName1Choice1 {
929    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
930    pub cd: Option<String>,
931    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
932    pub prtry: Option<String>,
933}
934
935impl PersonIdentificationSchemeName1Choice1 {
936    pub fn validate(&self) -> Result<(), ValidationError> {
937        if let Some(ref val) = self.cd {
938            if val.chars().count() < 1 {
939                return Err(ValidationError::new(
940                    1001,
941                    "cd is shorter than the minimum length of 1".to_string(),
942                ));
943            }
944            if val.chars().count() > 4 {
945                return Err(ValidationError::new(
946                    1002,
947                    "cd exceeds the maximum length of 4".to_string(),
948                ));
949            }
950        }
951        if let Some(ref val) = self.prtry {
952            if val.chars().count() < 1 {
953                return Err(ValidationError::new(
954                    1001,
955                    "prtry is shorter than the minimum length of 1".to_string(),
956                ));
957            }
958            if val.chars().count() > 35 {
959                return Err(ValidationError::new(
960                    1002,
961                    "prtry exceeds the maximum length of 35".to_string(),
962                ));
963            }
964            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
965            if !pattern.is_match(val) {
966                return Err(ValidationError::new(
967                    1005,
968                    "prtry does not match the required pattern".to_string(),
969                ));
970            }
971        }
972        Ok(())
973    }
974}
975
976// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
977#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
978pub struct PostalAddress241 {
979    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
980    pub dept: Option<String>,
981    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
982    pub sub_dept: Option<String>,
983    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
984    pub strt_nm: Option<String>,
985    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
986    pub bldg_nb: Option<String>,
987    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
988    pub bldg_nm: Option<String>,
989    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
990    pub flr: Option<String>,
991    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
992    pub pst_bx: Option<String>,
993    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
994    pub room: Option<String>,
995    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
996    pub pst_cd: Option<String>,
997    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
998    pub twn_nm: Option<String>,
999    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
1000    pub twn_lctn_nm: Option<String>,
1001    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
1002    pub dstrct_nm: Option<String>,
1003    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
1004    pub ctry_sub_dvsn: Option<String>,
1005    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
1006    pub ctry: Option<String>,
1007    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
1008    pub adr_line: Option<Vec<String>>,
1009}
1010
1011impl PostalAddress241 {
1012    pub fn validate(&self) -> Result<(), ValidationError> {
1013        if let Some(ref val) = self.dept {
1014            if val.chars().count() < 1 {
1015                return Err(ValidationError::new(
1016                    1001,
1017                    "dept is shorter than the minimum length of 1".to_string(),
1018                ));
1019            }
1020            if val.chars().count() > 70 {
1021                return Err(ValidationError::new(
1022                    1002,
1023                    "dept exceeds the maximum length of 70".to_string(),
1024                ));
1025            }
1026            let pattern = Regex::new(
1027                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1028            )
1029            .unwrap();
1030            if !pattern.is_match(val) {
1031                return Err(ValidationError::new(
1032                    1005,
1033                    "dept does not match the required pattern".to_string(),
1034                ));
1035            }
1036        }
1037        if let Some(ref val) = self.sub_dept {
1038            if val.chars().count() < 1 {
1039                return Err(ValidationError::new(
1040                    1001,
1041                    "sub_dept is shorter than the minimum length of 1".to_string(),
1042                ));
1043            }
1044            if val.chars().count() > 70 {
1045                return Err(ValidationError::new(
1046                    1002,
1047                    "sub_dept exceeds the maximum length of 70".to_string(),
1048                ));
1049            }
1050            let pattern = Regex::new(
1051                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1052            )
1053            .unwrap();
1054            if !pattern.is_match(val) {
1055                return Err(ValidationError::new(
1056                    1005,
1057                    "sub_dept does not match the required pattern".to_string(),
1058                ));
1059            }
1060        }
1061        if let Some(ref val) = self.strt_nm {
1062            if val.chars().count() < 1 {
1063                return Err(ValidationError::new(
1064                    1001,
1065                    "strt_nm is shorter than the minimum length of 1".to_string(),
1066                ));
1067            }
1068            if val.chars().count() > 70 {
1069                return Err(ValidationError::new(
1070                    1002,
1071                    "strt_nm exceeds the maximum length of 70".to_string(),
1072                ));
1073            }
1074            let pattern = Regex::new(
1075                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1076            )
1077            .unwrap();
1078            if !pattern.is_match(val) {
1079                return Err(ValidationError::new(
1080                    1005,
1081                    "strt_nm does not match the required pattern".to_string(),
1082                ));
1083            }
1084        }
1085        if let Some(ref val) = self.bldg_nb {
1086            if val.chars().count() < 1 {
1087                return Err(ValidationError::new(
1088                    1001,
1089                    "bldg_nb is shorter than the minimum length of 1".to_string(),
1090                ));
1091            }
1092            if val.chars().count() > 16 {
1093                return Err(ValidationError::new(
1094                    1002,
1095                    "bldg_nb exceeds the maximum length of 16".to_string(),
1096                ));
1097            }
1098            let pattern = Regex::new(
1099                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1100            )
1101            .unwrap();
1102            if !pattern.is_match(val) {
1103                return Err(ValidationError::new(
1104                    1005,
1105                    "bldg_nb does not match the required pattern".to_string(),
1106                ));
1107            }
1108        }
1109        if let Some(ref val) = self.bldg_nm {
1110            if val.chars().count() < 1 {
1111                return Err(ValidationError::new(
1112                    1001,
1113                    "bldg_nm is shorter than the minimum length of 1".to_string(),
1114                ));
1115            }
1116            if val.chars().count() > 35 {
1117                return Err(ValidationError::new(
1118                    1002,
1119                    "bldg_nm exceeds the maximum length of 35".to_string(),
1120                ));
1121            }
1122            let pattern = Regex::new(
1123                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1124            )
1125            .unwrap();
1126            if !pattern.is_match(val) {
1127                return Err(ValidationError::new(
1128                    1005,
1129                    "bldg_nm does not match the required pattern".to_string(),
1130                ));
1131            }
1132        }
1133        if let Some(ref val) = self.flr {
1134            if val.chars().count() < 1 {
1135                return Err(ValidationError::new(
1136                    1001,
1137                    "flr is shorter than the minimum length of 1".to_string(),
1138                ));
1139            }
1140            if val.chars().count() > 70 {
1141                return Err(ValidationError::new(
1142                    1002,
1143                    "flr exceeds the maximum length of 70".to_string(),
1144                ));
1145            }
1146            let pattern = Regex::new(
1147                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1148            )
1149            .unwrap();
1150            if !pattern.is_match(val) {
1151                return Err(ValidationError::new(
1152                    1005,
1153                    "flr does not match the required pattern".to_string(),
1154                ));
1155            }
1156        }
1157        if let Some(ref val) = self.pst_bx {
1158            if val.chars().count() < 1 {
1159                return Err(ValidationError::new(
1160                    1001,
1161                    "pst_bx is shorter than the minimum length of 1".to_string(),
1162                ));
1163            }
1164            if val.chars().count() > 16 {
1165                return Err(ValidationError::new(
1166                    1002,
1167                    "pst_bx exceeds the maximum length of 16".to_string(),
1168                ));
1169            }
1170            let pattern = Regex::new(
1171                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1172            )
1173            .unwrap();
1174            if !pattern.is_match(val) {
1175                return Err(ValidationError::new(
1176                    1005,
1177                    "pst_bx does not match the required pattern".to_string(),
1178                ));
1179            }
1180        }
1181        if let Some(ref val) = self.room {
1182            if val.chars().count() < 1 {
1183                return Err(ValidationError::new(
1184                    1001,
1185                    "room is shorter than the minimum length of 1".to_string(),
1186                ));
1187            }
1188            if val.chars().count() > 70 {
1189                return Err(ValidationError::new(
1190                    1002,
1191                    "room exceeds the maximum length of 70".to_string(),
1192                ));
1193            }
1194            let pattern = Regex::new(
1195                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1196            )
1197            .unwrap();
1198            if !pattern.is_match(val) {
1199                return Err(ValidationError::new(
1200                    1005,
1201                    "room does not match the required pattern".to_string(),
1202                ));
1203            }
1204        }
1205        if let Some(ref val) = self.pst_cd {
1206            if val.chars().count() < 1 {
1207                return Err(ValidationError::new(
1208                    1001,
1209                    "pst_cd is shorter than the minimum length of 1".to_string(),
1210                ));
1211            }
1212            if val.chars().count() > 16 {
1213                return Err(ValidationError::new(
1214                    1002,
1215                    "pst_cd exceeds the maximum length of 16".to_string(),
1216                ));
1217            }
1218            let pattern = Regex::new(
1219                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1220            )
1221            .unwrap();
1222            if !pattern.is_match(val) {
1223                return Err(ValidationError::new(
1224                    1005,
1225                    "pst_cd does not match the required pattern".to_string(),
1226                ));
1227            }
1228        }
1229        if let Some(ref val) = self.twn_nm {
1230            if val.chars().count() < 1 {
1231                return Err(ValidationError::new(
1232                    1001,
1233                    "twn_nm is shorter than the minimum length of 1".to_string(),
1234                ));
1235            }
1236            if val.chars().count() > 35 {
1237                return Err(ValidationError::new(
1238                    1002,
1239                    "twn_nm exceeds the maximum length of 35".to_string(),
1240                ));
1241            }
1242            let pattern = Regex::new(
1243                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1244            )
1245            .unwrap();
1246            if !pattern.is_match(val) {
1247                return Err(ValidationError::new(
1248                    1005,
1249                    "twn_nm does not match the required pattern".to_string(),
1250                ));
1251            }
1252        }
1253        if let Some(ref val) = self.twn_lctn_nm {
1254            if val.chars().count() < 1 {
1255                return Err(ValidationError::new(
1256                    1001,
1257                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
1258                ));
1259            }
1260            if val.chars().count() > 35 {
1261                return Err(ValidationError::new(
1262                    1002,
1263                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
1264                ));
1265            }
1266            let pattern = Regex::new(
1267                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1268            )
1269            .unwrap();
1270            if !pattern.is_match(val) {
1271                return Err(ValidationError::new(
1272                    1005,
1273                    "twn_lctn_nm does not match the required pattern".to_string(),
1274                ));
1275            }
1276        }
1277        if let Some(ref val) = self.dstrct_nm {
1278            if val.chars().count() < 1 {
1279                return Err(ValidationError::new(
1280                    1001,
1281                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
1282                ));
1283            }
1284            if val.chars().count() > 35 {
1285                return Err(ValidationError::new(
1286                    1002,
1287                    "dstrct_nm exceeds the maximum length of 35".to_string(),
1288                ));
1289            }
1290            let pattern = Regex::new(
1291                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1292            )
1293            .unwrap();
1294            if !pattern.is_match(val) {
1295                return Err(ValidationError::new(
1296                    1005,
1297                    "dstrct_nm does not match the required pattern".to_string(),
1298                ));
1299            }
1300        }
1301        if let Some(ref val) = self.ctry_sub_dvsn {
1302            if val.chars().count() < 1 {
1303                return Err(ValidationError::new(
1304                    1001,
1305                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
1306                ));
1307            }
1308            if val.chars().count() > 35 {
1309                return Err(ValidationError::new(
1310                    1002,
1311                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
1312                ));
1313            }
1314            let pattern = Regex::new(
1315                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1316            )
1317            .unwrap();
1318            if !pattern.is_match(val) {
1319                return Err(ValidationError::new(
1320                    1005,
1321                    "ctry_sub_dvsn does not match the required pattern".to_string(),
1322                ));
1323            }
1324        }
1325        if let Some(ref val) = self.ctry {
1326            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1327            if !pattern.is_match(val) {
1328                return Err(ValidationError::new(
1329                    1005,
1330                    "ctry does not match the required pattern".to_string(),
1331                ));
1332            }
1333        }
1334        if let Some(ref vec) = self.adr_line {
1335            for item in vec {
1336                if item.chars().count() < 1 {
1337                    return Err(ValidationError::new(
1338                        1001,
1339                        "adr_line is shorter than the minimum length of 1".to_string(),
1340                    ));
1341                }
1342                if item.chars().count() > 70 {
1343                    return Err(ValidationError::new(
1344                        1002,
1345                        "adr_line exceeds the maximum length of 70".to_string(),
1346                    ));
1347                }
1348                let pattern = Regex::new(
1349                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1350                )
1351                .unwrap();
1352                if !pattern.is_match(&item) {
1353                    return Err(ValidationError::new(
1354                        1005,
1355                        "adr_line does not match the required pattern".to_string(),
1356                    ));
1357                }
1358            }
1359        }
1360        Ok(())
1361    }
1362}