mx_message/document/
camt_109_001_01.rs

1// Plasmatic MX Message Parsing Library
2// https://github.com/GoPlasmatic/MXMessage
3//
4// Copyright (c) 2025 Plasmatic
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// You may obtain a copy of this library at
18// https://github.com/GoPlasmatic/MXMessage
19
20use crate::error::*;
21use regex::Regex;
22use serde::{Deserialize, Serialize};
23
24// AccountIdentification4Choice1: Unique identification of an account, as assigned by the account servicer, using an identification scheme.
25#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
26pub struct AccountIdentification4Choice1 {
27    #[serde(rename = "IBAN", skip_serializing_if = "Option::is_none")]
28    pub iban: Option<String>,
29    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
30    pub othr: Option<GenericAccountIdentification11>,
31}
32
33impl AccountIdentification4Choice1 {
34    pub fn validate(&self) -> Result<(), ValidationError> {
35        if let Some(ref val) = self.iban {
36            let pattern = Regex::new("[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}").unwrap();
37            if !pattern.is_match(val) {
38                return Err(ValidationError::new(
39                    1005,
40                    "iban does not match the required pattern".to_string(),
41                ));
42            }
43        }
44        if let Some(ref val) = self.othr {
45            val.validate()?
46        }
47        Ok(())
48    }
49}
50
51// AccountSchemeName1Choice1: Name of the identification scheme, in a free text form.
52#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
53pub struct AccountSchemeName1Choice1 {
54    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
55    pub cd: Option<String>,
56    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
57    pub prtry: Option<String>,
58}
59
60impl AccountSchemeName1Choice1 {
61    pub fn validate(&self) -> Result<(), ValidationError> {
62        if let Some(ref val) = self.cd {
63            if val.chars().count() < 1 {
64                return Err(ValidationError::new(
65                    1001,
66                    "cd is shorter than the minimum length of 1".to_string(),
67                ));
68            }
69            if val.chars().count() > 4 {
70                return Err(ValidationError::new(
71                    1002,
72                    "cd exceeds the maximum length of 4".to_string(),
73                ));
74            }
75        }
76        if let Some(ref val) = self.prtry {
77            if val.chars().count() < 1 {
78                return Err(ValidationError::new(
79                    1001,
80                    "prtry is shorter than the minimum length of 1".to_string(),
81                ));
82            }
83            if val.chars().count() > 35 {
84                return Err(ValidationError::new(
85                    1002,
86                    "prtry exceeds the maximum length of 35".to_string(),
87                ));
88            }
89            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
90            if !pattern.is_match(val) {
91                return Err(ValidationError::new(
92                    1005,
93                    "prtry does not match the required pattern".to_string(),
94                ));
95            }
96        }
97        Ok(())
98    }
99}
100
101// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
102#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
103pub struct BranchAndFinancialInstitutionIdentification61 {
104    #[serde(rename = "FinInstnId")]
105    pub fin_instn_id: FinancialInstitutionIdentification181,
106}
107
108impl BranchAndFinancialInstitutionIdentification61 {
109    pub fn validate(&self) -> Result<(), ValidationError> {
110        self.fin_instn_id.validate()?;
111        Ok(())
112    }
113}
114
115// CBPRAmount: CBPR_Amount
116#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
117pub struct CBPRAmount {
118    #[serde(rename = "@Ccy")]
119    pub ccy: String,
120    #[serde(rename = "$value")]
121    pub value: f64,
122}
123
124impl CBPRAmount {
125    pub fn validate(&self) -> Result<(), ValidationError> {
126        Ok(())
127    }
128}
129
130// CBPR_ChequeCancellationOrStopStatusCode: Cheque cancellation request or request to stop the cheque is accepted.
131#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
132pub enum CBPRChequeCancellationOrStopStatusCode {
133    #[default]
134    #[serde(rename = "RJCR")]
135    CodeRJCR,
136    #[serde(rename = "ACCR")]
137    CodeACCR,
138}
139
140impl CBPRChequeCancellationOrStopStatusCode {
141    pub fn validate(&self) -> Result<(), ValidationError> {
142        Ok(())
143    }
144}
145
146// CashAccount401: Specifies an alternate assumed name for the identification of the account.
147#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
148pub struct CashAccount401 {
149    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
150    pub id: Option<AccountIdentification4Choice1>,
151    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
152    pub tp: Option<CashAccountType2Choice1>,
153    #[serde(rename = "Ccy", skip_serializing_if = "Option::is_none")]
154    pub ccy: Option<String>,
155    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
156    pub nm: Option<String>,
157    #[serde(rename = "Prxy", skip_serializing_if = "Option::is_none")]
158    pub prxy: Option<ProxyAccountIdentification11>,
159}
160
161impl CashAccount401 {
162    pub fn validate(&self) -> Result<(), ValidationError> {
163        if let Some(ref val) = self.id {
164            val.validate()?
165        }
166        if let Some(ref val) = self.tp {
167            val.validate()?
168        }
169        if let Some(ref val) = self.ccy {
170            let pattern = Regex::new("[A-Z]{3,3}").unwrap();
171            if !pattern.is_match(val) {
172                return Err(ValidationError::new(
173                    1005,
174                    "ccy does not match the required pattern".to_string(),
175                ));
176            }
177        }
178        if let Some(ref val) = self.nm {
179            if val.chars().count() < 1 {
180                return Err(ValidationError::new(
181                    1001,
182                    "nm is shorter than the minimum length of 1".to_string(),
183                ));
184            }
185            if val.chars().count() > 70 {
186                return Err(ValidationError::new(
187                    1002,
188                    "nm exceeds the maximum length of 70".to_string(),
189                ));
190            }
191            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
192            if !pattern.is_match(val) {
193                return Err(ValidationError::new(
194                    1005,
195                    "nm does not match the required pattern".to_string(),
196                ));
197            }
198        }
199        if let Some(ref val) = self.prxy {
200            val.validate()?
201        }
202        Ok(())
203    }
204}
205
206// CashAccountType2Choice1: Nature or use of the account in a proprietary form.
207#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
208pub struct CashAccountType2Choice1 {
209    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
210    pub cd: Option<String>,
211    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
212    pub prtry: Option<String>,
213}
214
215impl CashAccountType2Choice1 {
216    pub fn validate(&self) -> Result<(), ValidationError> {
217        if let Some(ref val) = self.cd {
218            if val.chars().count() < 1 {
219                return Err(ValidationError::new(
220                    1001,
221                    "cd is shorter than the minimum length of 1".to_string(),
222                ));
223            }
224            if val.chars().count() > 4 {
225                return Err(ValidationError::new(
226                    1002,
227                    "cd exceeds the maximum length of 4".to_string(),
228                ));
229            }
230        }
231        if let Some(ref val) = self.prtry {
232            if val.chars().count() < 1 {
233                return Err(ValidationError::new(
234                    1001,
235                    "prtry is shorter than the minimum length of 1".to_string(),
236                ));
237            }
238            if val.chars().count() > 35 {
239                return Err(ValidationError::new(
240                    1002,
241                    "prtry exceeds the maximum length of 35".to_string(),
242                ));
243            }
244            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
245            if !pattern.is_match(val) {
246                return Err(ValidationError::new(
247                    1005,
248                    "prtry does not match the required pattern".to_string(),
249                ));
250            }
251        }
252        Ok(())
253    }
254}
255
256// Cheque141: Specifies the status of the cancellation or stop request.
257#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
258pub struct Cheque141 {
259    #[serde(rename = "InstrId", skip_serializing_if = "Option::is_none")]
260    pub instr_id: Option<String>,
261    #[serde(rename = "OrgnlInstrId")]
262    pub orgnl_instr_id: String,
263    #[serde(rename = "ChqNb")]
264    pub chq_nb: String,
265    #[serde(rename = "IsseDt")]
266    pub isse_dt: String,
267    #[serde(rename = "StlDt", skip_serializing_if = "Option::is_none")]
268    pub stl_dt: Option<String>,
269    #[serde(rename = "Amt")]
270    pub amt: CBPRAmount,
271    #[serde(rename = "FctvDt", skip_serializing_if = "Option::is_none")]
272    pub fctv_dt: Option<DateAndDateTime2Choice1>,
273    #[serde(rename = "DrwrAgt", skip_serializing_if = "Option::is_none")]
274    pub drwr_agt: Option<BranchAndFinancialInstitutionIdentification61>,
275    #[serde(rename = "DrwrAgtAcct", skip_serializing_if = "Option::is_none")]
276    pub drwr_agt_acct: Option<CashAccount401>,
277    #[serde(rename = "Pyee", skip_serializing_if = "Option::is_none")]
278    pub pyee: Option<PartyIdentification1351>,
279    #[serde(rename = "ChqCxlOrStopSts")]
280    pub chq_cxl_or_stop_sts: ChequeCancellationStatus11,
281}
282
283impl Cheque141 {
284    pub fn validate(&self) -> Result<(), ValidationError> {
285        if let Some(ref val) = self.instr_id {
286            if val.chars().count() < 1 {
287                return Err(ValidationError::new(
288                    1001,
289                    "instr_id is shorter than the minimum length of 1".to_string(),
290                ));
291            }
292            if val.chars().count() > 35 {
293                return Err(ValidationError::new(
294                    1002,
295                    "instr_id exceeds the maximum length of 35".to_string(),
296                ));
297            }
298            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
299            if !pattern.is_match(val) {
300                return Err(ValidationError::new(
301                    1005,
302                    "instr_id does not match the required pattern".to_string(),
303                ));
304            }
305        }
306        if self.orgnl_instr_id.chars().count() < 1 {
307            return Err(ValidationError::new(
308                1001,
309                "orgnl_instr_id is shorter than the minimum length of 1".to_string(),
310            ));
311        }
312        if self.orgnl_instr_id.chars().count() > 35 {
313            return Err(ValidationError::new(
314                1002,
315                "orgnl_instr_id exceeds the maximum length of 35".to_string(),
316            ));
317        }
318        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
319        if !pattern.is_match(&self.orgnl_instr_id) {
320            return Err(ValidationError::new(
321                1005,
322                "orgnl_instr_id does not match the required pattern".to_string(),
323            ));
324        }
325        if self.chq_nb.chars().count() < 1 {
326            return Err(ValidationError::new(
327                1001,
328                "chq_nb is shorter than the minimum length of 1".to_string(),
329            ));
330        }
331        if self.chq_nb.chars().count() > 16 {
332            return Err(ValidationError::new(
333                1002,
334                "chq_nb exceeds the maximum length of 16".to_string(),
335            ));
336        }
337        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
338        if !pattern.is_match(&self.chq_nb) {
339            return Err(ValidationError::new(
340                1005,
341                "chq_nb does not match the required pattern".to_string(),
342            ));
343        }
344        self.amt.validate()?;
345        if let Some(ref val) = self.fctv_dt {
346            val.validate()?
347        }
348        if let Some(ref val) = self.drwr_agt {
349            val.validate()?
350        }
351        if let Some(ref val) = self.drwr_agt_acct {
352            val.validate()?
353        }
354        if let Some(ref val) = self.pyee {
355            val.validate()?
356        }
357        self.chq_cxl_or_stop_sts.validate()?;
358        Ok(())
359    }
360}
361
362// ChequeCancellationOrStopReportV01: Specifies the details of the cheque.
363#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
364pub struct ChequeCancellationOrStopReportV01 {
365    #[serde(rename = "GrpHdr")]
366    pub grp_hdr: GroupHeader1031,
367    #[serde(rename = "Chq")]
368    pub chq: Cheque141,
369}
370
371impl ChequeCancellationOrStopReportV01 {
372    pub fn validate(&self) -> Result<(), ValidationError> {
373        self.grp_hdr.validate()?;
374        self.chq.validate()?;
375        Ok(())
376    }
377}
378
379// ChequeCancellationStatus1Choice1: Status, in a coded form, as published in an external code set.
380#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
381pub struct ChequeCancellationStatus1Choice1 {
382    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
383    pub cd: Option<CBPRChequeCancellationOrStopStatusCode>,
384}
385
386impl ChequeCancellationStatus1Choice1 {
387    pub fn validate(&self) -> Result<(), ValidationError> {
388        if let Some(ref val) = self.cd {
389            val.validate()?
390        }
391        Ok(())
392    }
393}
394
395// ChequeCancellationStatus11: Further details on the cancellation request reason.
396#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
397pub struct ChequeCancellationStatus11 {
398    #[serde(rename = "Orgtr", skip_serializing_if = "Option::is_none")]
399    pub orgtr: Option<ChequePartyRole1Code>,
400    #[serde(rename = "Sts")]
401    pub sts: ChequeCancellationStatus1Choice1,
402    #[serde(rename = "AddtlInf", skip_serializing_if = "Option::is_none")]
403    pub addtl_inf: Option<String>,
404}
405
406impl ChequeCancellationStatus11 {
407    pub fn validate(&self) -> Result<(), ValidationError> {
408        if let Some(ref val) = self.orgtr {
409            val.validate()?
410        }
411        self.sts.validate()?;
412        if let Some(ref val) = self.addtl_inf {
413            if val.chars().count() < 1 {
414                return Err(ValidationError::new(
415                    1001,
416                    "addtl_inf is shorter than the minimum length of 1".to_string(),
417                ));
418            }
419            if val.chars().count() > 140 {
420                return Err(ValidationError::new(
421                    1002,
422                    "addtl_inf exceeds the maximum length of 140".to_string(),
423                ));
424            }
425            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
426            if !pattern.is_match(val) {
427                return Err(ValidationError::new(
428                    1005,
429                    "addtl_inf does not match the required pattern".to_string(),
430                ));
431            }
432        }
433        Ok(())
434    }
435}
436
437// ChequePartyRole1Code: Party that issues a cheque ordering the drawee agent to pay a specific amount, upon demand, to the payee.
438#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
439pub enum ChequePartyRole1Code {
440    #[default]
441    #[serde(rename = "DWEA")]
442    CodeDWEA,
443    #[serde(rename = "DWRA")]
444    CodeDWRA,
445    #[serde(rename = "PAYE")]
446    CodePAYE,
447    #[serde(rename = "PAYR")]
448    CodePAYR,
449}
450
451impl ChequePartyRole1Code {
452    pub fn validate(&self) -> Result<(), ValidationError> {
453        Ok(())
454    }
455}
456
457// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
458#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
459pub struct ClearingSystemIdentification2Choice1 {
460    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
461    pub cd: Option<String>,
462}
463
464impl ClearingSystemIdentification2Choice1 {
465    pub fn validate(&self) -> Result<(), ValidationError> {
466        if let Some(ref val) = self.cd {
467            if val.chars().count() < 1 {
468                return Err(ValidationError::new(
469                    1001,
470                    "cd is shorter than the minimum length of 1".to_string(),
471                ));
472            }
473            if val.chars().count() > 5 {
474                return Err(ValidationError::new(
475                    1002,
476                    "cd exceeds the maximum length of 5".to_string(),
477                ));
478            }
479        }
480        Ok(())
481    }
482}
483
484// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
485#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
486pub struct ClearingSystemMemberIdentification21 {
487    #[serde(rename = "ClrSysId")]
488    pub clr_sys_id: ClearingSystemIdentification2Choice1,
489    #[serde(rename = "MmbId")]
490    pub mmb_id: String,
491}
492
493impl ClearingSystemMemberIdentification21 {
494    pub fn validate(&self) -> Result<(), ValidationError> {
495        self.clr_sys_id.validate()?;
496        if self.mmb_id.chars().count() < 1 {
497            return Err(ValidationError::new(
498                1001,
499                "mmb_id is shorter than the minimum length of 1".to_string(),
500            ));
501        }
502        if self.mmb_id.chars().count() > 28 {
503            return Err(ValidationError::new(
504                1002,
505                "mmb_id exceeds the maximum length of 28".to_string(),
506            ));
507        }
508        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
509        if !pattern.is_match(&self.mmb_id) {
510            return Err(ValidationError::new(
511                1005,
512                "mmb_id does not match the required pattern".to_string(),
513            ));
514        }
515        Ok(())
516    }
517}
518
519// DateAndDateTime2Choice1: Specified date.
520#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
521pub struct DateAndDateTime2Choice1 {
522    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
523    pub dt: Option<String>,
524}
525
526impl DateAndDateTime2Choice1 {
527    pub fn validate(&self) -> Result<(), ValidationError> {
528        Ok(())
529    }
530}
531
532// DateAndPlaceOfBirth11: Country where a person was born.
533#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
534pub struct DateAndPlaceOfBirth11 {
535    #[serde(rename = "BirthDt")]
536    pub birth_dt: String,
537    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
538    pub prvc_of_birth: Option<String>,
539    #[serde(rename = "CityOfBirth")]
540    pub city_of_birth: String,
541    #[serde(rename = "CtryOfBirth")]
542    pub ctry_of_birth: String,
543}
544
545impl DateAndPlaceOfBirth11 {
546    pub fn validate(&self) -> Result<(), ValidationError> {
547        if let Some(ref val) = self.prvc_of_birth {
548            if val.chars().count() < 1 {
549                return Err(ValidationError::new(
550                    1001,
551                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
552                ));
553            }
554            if val.chars().count() > 35 {
555                return Err(ValidationError::new(
556                    1002,
557                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
558                ));
559            }
560            let pattern = Regex::new(
561                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
562            )
563            .unwrap();
564            if !pattern.is_match(val) {
565                return Err(ValidationError::new(
566                    1005,
567                    "prvc_of_birth does not match the required pattern".to_string(),
568                ));
569            }
570        }
571        if self.city_of_birth.chars().count() < 1 {
572            return Err(ValidationError::new(
573                1001,
574                "city_of_birth is shorter than the minimum length of 1".to_string(),
575            ));
576        }
577        if self.city_of_birth.chars().count() > 35 {
578            return Err(ValidationError::new(
579                1002,
580                "city_of_birth exceeds the maximum length of 35".to_string(),
581            ));
582        }
583        let pattern =
584            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
585                .unwrap();
586        if !pattern.is_match(&self.city_of_birth) {
587            return Err(ValidationError::new(
588                1005,
589                "city_of_birth does not match the required pattern".to_string(),
590            ));
591        }
592        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
593        if !pattern.is_match(&self.ctry_of_birth) {
594            return Err(ValidationError::new(
595                1005,
596                "ctry_of_birth does not match the required pattern".to_string(),
597            ));
598        }
599        Ok(())
600    }
601}
602
603// FinancialInstitutionIdentification181: Information that locates and identifies a specific address, as defined by postal services.
604#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
605pub struct FinancialInstitutionIdentification181 {
606    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
607    pub bicfi: Option<String>,
608    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
609    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
610    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
611    pub lei: Option<String>,
612    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
613    pub nm: Option<String>,
614    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
615    pub pstl_adr: Option<PostalAddress241>,
616}
617
618impl FinancialInstitutionIdentification181 {
619    pub fn validate(&self) -> Result<(), ValidationError> {
620        if let Some(ref val) = self.bicfi {
621            let pattern =
622                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
623            if !pattern.is_match(val) {
624                return Err(ValidationError::new(
625                    1005,
626                    "bicfi does not match the required pattern".to_string(),
627                ));
628            }
629        }
630        if let Some(ref val) = self.clr_sys_mmb_id {
631            val.validate()?
632        }
633        if let Some(ref val) = self.lei {
634            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
635            if !pattern.is_match(val) {
636                return Err(ValidationError::new(
637                    1005,
638                    "lei does not match the required pattern".to_string(),
639                ));
640            }
641        }
642        if let Some(ref val) = self.nm {
643            if val.chars().count() < 1 {
644                return Err(ValidationError::new(
645                    1001,
646                    "nm is shorter than the minimum length of 1".to_string(),
647                ));
648            }
649            if val.chars().count() > 140 {
650                return Err(ValidationError::new(
651                    1002,
652                    "nm exceeds the maximum length of 140".to_string(),
653                ));
654            }
655            let pattern = Regex::new(
656                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
657            )
658            .unwrap();
659            if !pattern.is_match(val) {
660                return Err(ValidationError::new(
661                    1005,
662                    "nm does not match the required pattern".to_string(),
663                ));
664            }
665        }
666        if let Some(ref val) = self.pstl_adr {
667            val.validate()?
668        }
669        Ok(())
670    }
671}
672
673// GenericAccountIdentification11: Entity that assigns the identification.
674#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
675pub struct GenericAccountIdentification11 {
676    #[serde(rename = "Id")]
677    pub id: String,
678    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
679    pub schme_nm: Option<AccountSchemeName1Choice1>,
680    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
681    pub issr: Option<String>,
682}
683
684impl GenericAccountIdentification11 {
685    pub fn validate(&self) -> Result<(), ValidationError> {
686        if self.id.chars().count() < 1 {
687            return Err(ValidationError::new(
688                1001,
689                "id is shorter than the minimum length of 1".to_string(),
690            ));
691        }
692        if self.id.chars().count() > 34 {
693            return Err(ValidationError::new(
694                1002,
695                "id exceeds the maximum length of 34".to_string(),
696            ));
697        }
698        let pattern = Regex::new("([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]*(/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ])?)*)").unwrap();
699        if !pattern.is_match(&self.id) {
700            return Err(ValidationError::new(
701                1005,
702                "id does not match the required pattern".to_string(),
703            ));
704        }
705        if let Some(ref val) = self.schme_nm {
706            val.validate()?
707        }
708        if let Some(ref val) = self.issr {
709            if val.chars().count() < 1 {
710                return Err(ValidationError::new(
711                    1001,
712                    "issr is shorter than the minimum length of 1".to_string(),
713                ));
714            }
715            if val.chars().count() > 35 {
716                return Err(ValidationError::new(
717                    1002,
718                    "issr exceeds the maximum length of 35".to_string(),
719                ));
720            }
721            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
722            if !pattern.is_match(val) {
723                return Err(ValidationError::new(
724                    1005,
725                    "issr does not match the required pattern".to_string(),
726                ));
727            }
728        }
729        Ok(())
730    }
731}
732
733// GenericOrganisationIdentification11: Entity that assigns the identification.
734#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
735pub struct GenericOrganisationIdentification11 {
736    #[serde(rename = "Id")]
737    pub id: String,
738    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
739    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice1>,
740    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
741    pub issr: Option<String>,
742}
743
744impl GenericOrganisationIdentification11 {
745    pub fn validate(&self) -> Result<(), ValidationError> {
746        if self.id.chars().count() < 1 {
747            return Err(ValidationError::new(
748                1001,
749                "id is shorter than the minimum length of 1".to_string(),
750            ));
751        }
752        if self.id.chars().count() > 35 {
753            return Err(ValidationError::new(
754                1002,
755                "id exceeds the maximum length of 35".to_string(),
756            ));
757        }
758        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
759        if !pattern.is_match(&self.id) {
760            return Err(ValidationError::new(
761                1005,
762                "id does not match the required pattern".to_string(),
763            ));
764        }
765        if let Some(ref val) = self.schme_nm {
766            val.validate()?
767        }
768        if let Some(ref val) = self.issr {
769            if val.chars().count() < 1 {
770                return Err(ValidationError::new(
771                    1001,
772                    "issr is shorter than the minimum length of 1".to_string(),
773                ));
774            }
775            if val.chars().count() > 35 {
776                return Err(ValidationError::new(
777                    1002,
778                    "issr exceeds the maximum length of 35".to_string(),
779                ));
780            }
781            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
782            if !pattern.is_match(val) {
783                return Err(ValidationError::new(
784                    1005,
785                    "issr does not match the required pattern".to_string(),
786                ));
787            }
788        }
789        Ok(())
790    }
791}
792
793// GenericPersonIdentification11: Entity that assigns the identification.
794#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
795pub struct GenericPersonIdentification11 {
796    #[serde(rename = "Id")]
797    pub id: String,
798    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
799    pub schme_nm: Option<PersonIdentificationSchemeName1Choice1>,
800    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
801    pub issr: Option<String>,
802}
803
804impl GenericPersonIdentification11 {
805    pub fn validate(&self) -> Result<(), ValidationError> {
806        if self.id.chars().count() < 1 {
807            return Err(ValidationError::new(
808                1001,
809                "id is shorter than the minimum length of 1".to_string(),
810            ));
811        }
812        if self.id.chars().count() > 35 {
813            return Err(ValidationError::new(
814                1002,
815                "id exceeds the maximum length of 35".to_string(),
816            ));
817        }
818        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
819        if !pattern.is_match(&self.id) {
820            return Err(ValidationError::new(
821                1005,
822                "id does not match the required pattern".to_string(),
823            ));
824        }
825        if let Some(ref val) = self.schme_nm {
826            val.validate()?
827        }
828        if let Some(ref val) = self.issr {
829            if val.chars().count() < 1 {
830                return Err(ValidationError::new(
831                    1001,
832                    "issr is shorter than the minimum length of 1".to_string(),
833                ));
834            }
835            if val.chars().count() > 35 {
836                return Err(ValidationError::new(
837                    1002,
838                    "issr exceeds the maximum length of 35".to_string(),
839                ));
840            }
841            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
842            if !pattern.is_match(val) {
843                return Err(ValidationError::new(
844                    1005,
845                    "issr does not match the required pattern".to_string(),
846                ));
847            }
848        }
849        Ok(())
850    }
851}
852
853// GroupHeader1031: Total of all individual amounts included in the message, irrespective of currencies.
854#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
855pub struct GroupHeader1031 {
856    #[serde(rename = "MsgId")]
857    pub msg_id: String,
858    #[serde(rename = "CreDtTm")]
859    pub cre_dt_tm: String,
860    #[serde(rename = "NbOfChqs")]
861    pub nb_of_chqs: String,
862    #[serde(rename = "CtrlSum", skip_serializing_if = "Option::is_none")]
863    pub ctrl_sum: Option<f64>,
864}
865
866impl GroupHeader1031 {
867    pub fn validate(&self) -> Result<(), ValidationError> {
868        if self.msg_id.chars().count() < 1 {
869            return Err(ValidationError::new(
870                1001,
871                "msg_id is shorter than the minimum length of 1".to_string(),
872            ));
873        }
874        if self.msg_id.chars().count() > 16 {
875            return Err(ValidationError::new(
876                1002,
877                "msg_id exceeds the maximum length of 16".to_string(),
878            ));
879        }
880        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
881        if !pattern.is_match(&self.msg_id) {
882            return Err(ValidationError::new(
883                1005,
884                "msg_id does not match the required pattern".to_string(),
885            ));
886        }
887        let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
888        if !pattern.is_match(&self.cre_dt_tm) {
889            return Err(ValidationError::new(
890                1005,
891                "cre_dt_tm does not match the required pattern".to_string(),
892            ));
893        }
894        let pattern = Regex::new("[0-9]{1,15}").unwrap();
895        if !pattern.is_match(&self.nb_of_chqs) {
896            return Err(ValidationError::new(
897                1005,
898                "nb_of_chqs does not match the required pattern".to_string(),
899            ));
900        }
901        Ok(())
902    }
903}
904
905// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
906#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
907pub struct OrganisationIdentification291 {
908    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
909    pub any_bic: Option<String>,
910    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
911    pub lei: Option<String>,
912    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
913    pub othr: Option<Vec<GenericOrganisationIdentification11>>,
914}
915
916impl OrganisationIdentification291 {
917    pub fn validate(&self) -> Result<(), ValidationError> {
918        if let Some(ref val) = self.any_bic {
919            let pattern =
920                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
921            if !pattern.is_match(val) {
922                return Err(ValidationError::new(
923                    1005,
924                    "any_bic does not match the required pattern".to_string(),
925                ));
926            }
927        }
928        if let Some(ref val) = self.lei {
929            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
930            if !pattern.is_match(val) {
931                return Err(ValidationError::new(
932                    1005,
933                    "lei does not match the required pattern".to_string(),
934                ));
935            }
936        }
937        if let Some(ref vec) = self.othr {
938            for item in vec {
939                item.validate()?
940            }
941        }
942        Ok(())
943    }
944}
945
946// OrganisationIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
947#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
948pub struct OrganisationIdentificationSchemeName1Choice1 {
949    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
950    pub cd: Option<String>,
951    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
952    pub prtry: Option<String>,
953}
954
955impl OrganisationIdentificationSchemeName1Choice1 {
956    pub fn validate(&self) -> Result<(), ValidationError> {
957        if let Some(ref val) = self.cd {
958            if val.chars().count() < 1 {
959                return Err(ValidationError::new(
960                    1001,
961                    "cd is shorter than the minimum length of 1".to_string(),
962                ));
963            }
964            if val.chars().count() > 4 {
965                return Err(ValidationError::new(
966                    1002,
967                    "cd exceeds the maximum length of 4".to_string(),
968                ));
969            }
970        }
971        if let Some(ref val) = self.prtry {
972            if val.chars().count() < 1 {
973                return Err(ValidationError::new(
974                    1001,
975                    "prtry is shorter than the minimum length of 1".to_string(),
976                ));
977            }
978            if val.chars().count() > 35 {
979                return Err(ValidationError::new(
980                    1002,
981                    "prtry exceeds the maximum length of 35".to_string(),
982                ));
983            }
984            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
985            if !pattern.is_match(val) {
986                return Err(ValidationError::new(
987                    1005,
988                    "prtry does not match the required pattern".to_string(),
989                ));
990            }
991        }
992        Ok(())
993    }
994}
995
996// Party38Choice1: Unique and unambiguous identification of a person, for example a passport.
997#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
998pub struct Party38Choice1 {
999    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1000    pub org_id: Option<OrganisationIdentification291>,
1001    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1002    pub prvt_id: Option<PersonIdentification131>,
1003}
1004
1005impl Party38Choice1 {
1006    pub fn validate(&self) -> Result<(), ValidationError> {
1007        if let Some(ref val) = self.org_id {
1008            val.validate()?
1009        }
1010        if let Some(ref val) = self.prvt_id {
1011            val.validate()?
1012        }
1013        Ok(())
1014    }
1015}
1016
1017// 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.
1018#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1019pub struct PartyIdentification1351 {
1020    #[serde(rename = "Nm")]
1021    pub nm: String,
1022    #[serde(rename = "PstlAdr")]
1023    pub pstl_adr: PostalAddress241,
1024    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1025    pub id: Option<Party38Choice1>,
1026    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1027    pub ctry_of_res: Option<String>,
1028}
1029
1030impl PartyIdentification1351 {
1031    pub fn validate(&self) -> Result<(), ValidationError> {
1032        if self.nm.chars().count() < 1 {
1033            return Err(ValidationError::new(
1034                1001,
1035                "nm is shorter than the minimum length of 1".to_string(),
1036            ));
1037        }
1038        if self.nm.chars().count() > 140 {
1039            return Err(ValidationError::new(
1040                1002,
1041                "nm exceeds the maximum length of 140".to_string(),
1042            ));
1043        }
1044        let pattern =
1045            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
1046                .unwrap();
1047        if !pattern.is_match(&self.nm) {
1048            return Err(ValidationError::new(
1049                1005,
1050                "nm does not match the required pattern".to_string(),
1051            ));
1052        }
1053        self.pstl_adr.validate()?;
1054        if let Some(ref val) = self.id {
1055            val.validate()?
1056        }
1057        if let Some(ref val) = self.ctry_of_res {
1058            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1059            if !pattern.is_match(val) {
1060                return Err(ValidationError::new(
1061                    1005,
1062                    "ctry_of_res does not match the required pattern".to_string(),
1063                ));
1064            }
1065        }
1066        Ok(())
1067    }
1068}
1069
1070// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
1071#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1072pub struct PersonIdentification131 {
1073    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1074    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
1075    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1076    pub othr: Option<Vec<GenericPersonIdentification11>>,
1077}
1078
1079impl PersonIdentification131 {
1080    pub fn validate(&self) -> Result<(), ValidationError> {
1081        if let Some(ref val) = self.dt_and_plc_of_birth {
1082            val.validate()?
1083        }
1084        if let Some(ref vec) = self.othr {
1085            for item in vec {
1086                item.validate()?
1087            }
1088        }
1089        Ok(())
1090    }
1091}
1092
1093// PersonIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
1094#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1095pub struct PersonIdentificationSchemeName1Choice1 {
1096    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1097    pub cd: Option<String>,
1098    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1099    pub prtry: Option<String>,
1100}
1101
1102impl PersonIdentificationSchemeName1Choice1 {
1103    pub fn validate(&self) -> Result<(), ValidationError> {
1104        if let Some(ref val) = self.cd {
1105            if val.chars().count() < 1 {
1106                return Err(ValidationError::new(
1107                    1001,
1108                    "cd is shorter than the minimum length of 1".to_string(),
1109                ));
1110            }
1111            if val.chars().count() > 4 {
1112                return Err(ValidationError::new(
1113                    1002,
1114                    "cd exceeds the maximum length of 4".to_string(),
1115                ));
1116            }
1117        }
1118        if let Some(ref val) = self.prtry {
1119            if val.chars().count() < 1 {
1120                return Err(ValidationError::new(
1121                    1001,
1122                    "prtry is shorter than the minimum length of 1".to_string(),
1123                ));
1124            }
1125            if val.chars().count() > 35 {
1126                return Err(ValidationError::new(
1127                    1002,
1128                    "prtry exceeds the maximum length of 35".to_string(),
1129                ));
1130            }
1131            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1132            if !pattern.is_match(val) {
1133                return Err(ValidationError::new(
1134                    1005,
1135                    "prtry does not match the required pattern".to_string(),
1136                ));
1137            }
1138        }
1139        Ok(())
1140    }
1141}
1142
1143// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
1144#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1145pub struct PostalAddress241 {
1146    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
1147    pub dept: Option<String>,
1148    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
1149    pub sub_dept: Option<String>,
1150    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
1151    pub strt_nm: Option<String>,
1152    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
1153    pub bldg_nb: Option<String>,
1154    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
1155    pub bldg_nm: Option<String>,
1156    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
1157    pub flr: Option<String>,
1158    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
1159    pub pst_bx: Option<String>,
1160    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
1161    pub room: Option<String>,
1162    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
1163    pub pst_cd: Option<String>,
1164    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
1165    pub twn_nm: Option<String>,
1166    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
1167    pub twn_lctn_nm: Option<String>,
1168    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
1169    pub dstrct_nm: Option<String>,
1170    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
1171    pub ctry_sub_dvsn: Option<String>,
1172    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
1173    pub ctry: Option<String>,
1174    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
1175    pub adr_line: Option<Vec<String>>,
1176}
1177
1178impl PostalAddress241 {
1179    pub fn validate(&self) -> Result<(), ValidationError> {
1180        if let Some(ref val) = self.dept {
1181            if val.chars().count() < 1 {
1182                return Err(ValidationError::new(
1183                    1001,
1184                    "dept is shorter than the minimum length of 1".to_string(),
1185                ));
1186            }
1187            if val.chars().count() > 70 {
1188                return Err(ValidationError::new(
1189                    1002,
1190                    "dept exceeds the maximum length of 70".to_string(),
1191                ));
1192            }
1193            let pattern = Regex::new(
1194                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1195            )
1196            .unwrap();
1197            if !pattern.is_match(val) {
1198                return Err(ValidationError::new(
1199                    1005,
1200                    "dept does not match the required pattern".to_string(),
1201                ));
1202            }
1203        }
1204        if let Some(ref val) = self.sub_dept {
1205            if val.chars().count() < 1 {
1206                return Err(ValidationError::new(
1207                    1001,
1208                    "sub_dept is shorter than the minimum length of 1".to_string(),
1209                ));
1210            }
1211            if val.chars().count() > 70 {
1212                return Err(ValidationError::new(
1213                    1002,
1214                    "sub_dept exceeds the maximum length of 70".to_string(),
1215                ));
1216            }
1217            let pattern = Regex::new(
1218                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1219            )
1220            .unwrap();
1221            if !pattern.is_match(val) {
1222                return Err(ValidationError::new(
1223                    1005,
1224                    "sub_dept does not match the required pattern".to_string(),
1225                ));
1226            }
1227        }
1228        if let Some(ref val) = self.strt_nm {
1229            if val.chars().count() < 1 {
1230                return Err(ValidationError::new(
1231                    1001,
1232                    "strt_nm is shorter than the minimum length of 1".to_string(),
1233                ));
1234            }
1235            if val.chars().count() > 70 {
1236                return Err(ValidationError::new(
1237                    1002,
1238                    "strt_nm exceeds the maximum length of 70".to_string(),
1239                ));
1240            }
1241            let pattern = Regex::new(
1242                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1243            )
1244            .unwrap();
1245            if !pattern.is_match(val) {
1246                return Err(ValidationError::new(
1247                    1005,
1248                    "strt_nm does not match the required pattern".to_string(),
1249                ));
1250            }
1251        }
1252        if let Some(ref val) = self.bldg_nb {
1253            if val.chars().count() < 1 {
1254                return Err(ValidationError::new(
1255                    1001,
1256                    "bldg_nb is shorter than the minimum length of 1".to_string(),
1257                ));
1258            }
1259            if val.chars().count() > 16 {
1260                return Err(ValidationError::new(
1261                    1002,
1262                    "bldg_nb exceeds the maximum length of 16".to_string(),
1263                ));
1264            }
1265            let pattern = Regex::new(
1266                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1267            )
1268            .unwrap();
1269            if !pattern.is_match(val) {
1270                return Err(ValidationError::new(
1271                    1005,
1272                    "bldg_nb does not match the required pattern".to_string(),
1273                ));
1274            }
1275        }
1276        if let Some(ref val) = self.bldg_nm {
1277            if val.chars().count() < 1 {
1278                return Err(ValidationError::new(
1279                    1001,
1280                    "bldg_nm is shorter than the minimum length of 1".to_string(),
1281                ));
1282            }
1283            if val.chars().count() > 35 {
1284                return Err(ValidationError::new(
1285                    1002,
1286                    "bldg_nm exceeds the maximum length of 35".to_string(),
1287                ));
1288            }
1289            let pattern = Regex::new(
1290                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1291            )
1292            .unwrap();
1293            if !pattern.is_match(val) {
1294                return Err(ValidationError::new(
1295                    1005,
1296                    "bldg_nm does not match the required pattern".to_string(),
1297                ));
1298            }
1299        }
1300        if let Some(ref val) = self.flr {
1301            if val.chars().count() < 1 {
1302                return Err(ValidationError::new(
1303                    1001,
1304                    "flr is shorter than the minimum length of 1".to_string(),
1305                ));
1306            }
1307            if val.chars().count() > 70 {
1308                return Err(ValidationError::new(
1309                    1002,
1310                    "flr exceeds the maximum length of 70".to_string(),
1311                ));
1312            }
1313            let pattern = Regex::new(
1314                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1315            )
1316            .unwrap();
1317            if !pattern.is_match(val) {
1318                return Err(ValidationError::new(
1319                    1005,
1320                    "flr does not match the required pattern".to_string(),
1321                ));
1322            }
1323        }
1324        if let Some(ref val) = self.pst_bx {
1325            if val.chars().count() < 1 {
1326                return Err(ValidationError::new(
1327                    1001,
1328                    "pst_bx is shorter than the minimum length of 1".to_string(),
1329                ));
1330            }
1331            if val.chars().count() > 16 {
1332                return Err(ValidationError::new(
1333                    1002,
1334                    "pst_bx exceeds the maximum length of 16".to_string(),
1335                ));
1336            }
1337            let pattern = Regex::new(
1338                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1339            )
1340            .unwrap();
1341            if !pattern.is_match(val) {
1342                return Err(ValidationError::new(
1343                    1005,
1344                    "pst_bx does not match the required pattern".to_string(),
1345                ));
1346            }
1347        }
1348        if let Some(ref val) = self.room {
1349            if val.chars().count() < 1 {
1350                return Err(ValidationError::new(
1351                    1001,
1352                    "room is shorter than the minimum length of 1".to_string(),
1353                ));
1354            }
1355            if val.chars().count() > 70 {
1356                return Err(ValidationError::new(
1357                    1002,
1358                    "room exceeds the maximum length of 70".to_string(),
1359                ));
1360            }
1361            let pattern = Regex::new(
1362                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1363            )
1364            .unwrap();
1365            if !pattern.is_match(val) {
1366                return Err(ValidationError::new(
1367                    1005,
1368                    "room does not match the required pattern".to_string(),
1369                ));
1370            }
1371        }
1372        if let Some(ref val) = self.pst_cd {
1373            if val.chars().count() < 1 {
1374                return Err(ValidationError::new(
1375                    1001,
1376                    "pst_cd is shorter than the minimum length of 1".to_string(),
1377                ));
1378            }
1379            if val.chars().count() > 16 {
1380                return Err(ValidationError::new(
1381                    1002,
1382                    "pst_cd exceeds the maximum length of 16".to_string(),
1383                ));
1384            }
1385            let pattern = Regex::new(
1386                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1387            )
1388            .unwrap();
1389            if !pattern.is_match(val) {
1390                return Err(ValidationError::new(
1391                    1005,
1392                    "pst_cd does not match the required pattern".to_string(),
1393                ));
1394            }
1395        }
1396        if let Some(ref val) = self.twn_nm {
1397            if val.chars().count() < 1 {
1398                return Err(ValidationError::new(
1399                    1001,
1400                    "twn_nm is shorter than the minimum length of 1".to_string(),
1401                ));
1402            }
1403            if val.chars().count() > 35 {
1404                return Err(ValidationError::new(
1405                    1002,
1406                    "twn_nm exceeds the maximum length of 35".to_string(),
1407                ));
1408            }
1409            let pattern = Regex::new(
1410                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1411            )
1412            .unwrap();
1413            if !pattern.is_match(val) {
1414                return Err(ValidationError::new(
1415                    1005,
1416                    "twn_nm does not match the required pattern".to_string(),
1417                ));
1418            }
1419        }
1420        if let Some(ref val) = self.twn_lctn_nm {
1421            if val.chars().count() < 1 {
1422                return Err(ValidationError::new(
1423                    1001,
1424                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
1425                ));
1426            }
1427            if val.chars().count() > 35 {
1428                return Err(ValidationError::new(
1429                    1002,
1430                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
1431                ));
1432            }
1433            let pattern = Regex::new(
1434                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1435            )
1436            .unwrap();
1437            if !pattern.is_match(val) {
1438                return Err(ValidationError::new(
1439                    1005,
1440                    "twn_lctn_nm does not match the required pattern".to_string(),
1441                ));
1442            }
1443        }
1444        if let Some(ref val) = self.dstrct_nm {
1445            if val.chars().count() < 1 {
1446                return Err(ValidationError::new(
1447                    1001,
1448                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
1449                ));
1450            }
1451            if val.chars().count() > 35 {
1452                return Err(ValidationError::new(
1453                    1002,
1454                    "dstrct_nm exceeds the maximum length of 35".to_string(),
1455                ));
1456            }
1457            let pattern = Regex::new(
1458                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1459            )
1460            .unwrap();
1461            if !pattern.is_match(val) {
1462                return Err(ValidationError::new(
1463                    1005,
1464                    "dstrct_nm does not match the required pattern".to_string(),
1465                ));
1466            }
1467        }
1468        if let Some(ref val) = self.ctry_sub_dvsn {
1469            if val.chars().count() < 1 {
1470                return Err(ValidationError::new(
1471                    1001,
1472                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
1473                ));
1474            }
1475            if val.chars().count() > 35 {
1476                return Err(ValidationError::new(
1477                    1002,
1478                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
1479                ));
1480            }
1481            let pattern = Regex::new(
1482                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1483            )
1484            .unwrap();
1485            if !pattern.is_match(val) {
1486                return Err(ValidationError::new(
1487                    1005,
1488                    "ctry_sub_dvsn does not match the required pattern".to_string(),
1489                ));
1490            }
1491        }
1492        if let Some(ref val) = self.ctry {
1493            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1494            if !pattern.is_match(val) {
1495                return Err(ValidationError::new(
1496                    1005,
1497                    "ctry does not match the required pattern".to_string(),
1498                ));
1499            }
1500        }
1501        if let Some(ref vec) = self.adr_line {
1502            for item in vec {
1503                if item.chars().count() < 1 {
1504                    return Err(ValidationError::new(
1505                        1001,
1506                        "adr_line is shorter than the minimum length of 1".to_string(),
1507                    ));
1508                }
1509                if item.chars().count() > 70 {
1510                    return Err(ValidationError::new(
1511                        1002,
1512                        "adr_line exceeds the maximum length of 70".to_string(),
1513                    ));
1514                }
1515                let pattern = Regex::new(
1516                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1517                )
1518                .unwrap();
1519                if !pattern.is_match(&item) {
1520                    return Err(ValidationError::new(
1521                        1005,
1522                        "adr_line does not match the required pattern".to_string(),
1523                    ));
1524                }
1525            }
1526        }
1527        Ok(())
1528    }
1529}
1530
1531// ProxyAccountIdentification11: Identification used to indicate the account identification under another specified name.
1532#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1533pub struct ProxyAccountIdentification11 {
1534    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
1535    pub tp: Option<ProxyAccountType1Choice1>,
1536    #[serde(rename = "Id")]
1537    pub id: String,
1538}
1539
1540impl ProxyAccountIdentification11 {
1541    pub fn validate(&self) -> Result<(), ValidationError> {
1542        if let Some(ref val) = self.tp {
1543            val.validate()?
1544        }
1545        if self.id.chars().count() < 1 {
1546            return Err(ValidationError::new(
1547                1001,
1548                "id is shorter than the minimum length of 1".to_string(),
1549            ));
1550        }
1551        if self.id.chars().count() > 320 {
1552            return Err(ValidationError::new(
1553                1002,
1554                "id exceeds the maximum length of 320".to_string(),
1555            ));
1556        }
1557        let pattern =
1558            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
1559                .unwrap();
1560        if !pattern.is_match(&self.id) {
1561            return Err(ValidationError::new(
1562                1005,
1563                "id does not match the required pattern".to_string(),
1564            ));
1565        }
1566        Ok(())
1567    }
1568}
1569
1570// ProxyAccountType1Choice1: Name of the identification scheme, in a free text form.
1571#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1572pub struct ProxyAccountType1Choice1 {
1573    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1574    pub cd: Option<String>,
1575    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1576    pub prtry: Option<String>,
1577}
1578
1579impl ProxyAccountType1Choice1 {
1580    pub fn validate(&self) -> Result<(), ValidationError> {
1581        if let Some(ref val) = self.cd {
1582            if val.chars().count() < 1 {
1583                return Err(ValidationError::new(
1584                    1001,
1585                    "cd is shorter than the minimum length of 1".to_string(),
1586                ));
1587            }
1588            if val.chars().count() > 4 {
1589                return Err(ValidationError::new(
1590                    1002,
1591                    "cd exceeds the maximum length of 4".to_string(),
1592                ));
1593            }
1594        }
1595        if let Some(ref val) = self.prtry {
1596            if val.chars().count() < 1 {
1597                return Err(ValidationError::new(
1598                    1001,
1599                    "prtry is shorter than the minimum length of 1".to_string(),
1600                ));
1601            }
1602            if val.chars().count() > 35 {
1603                return Err(ValidationError::new(
1604                    1002,
1605                    "prtry exceeds the maximum length of 35".to_string(),
1606                ));
1607            }
1608            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1609            if !pattern.is_match(val) {
1610                return Err(ValidationError::new(
1611                    1005,
1612                    "prtry does not match the required pattern".to_string(),
1613                ));
1614            }
1615        }
1616        Ok(())
1617    }
1618}