mx_message/document/
pain_001_001_09.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// AccountIdentification4Choice: 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 AccountIdentification4Choice {
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<GenericAccountIdentification1>,
31}
32
33impl AccountIdentification4Choice {
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// AccountSchemeName1Choice: Name of the identification scheme, in a free text form.
52#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
53pub struct AccountSchemeName1Choice {
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 AccountSchemeName1Choice {
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        }
90        Ok(())
91    }
92}
93
94// ActiveOrHistoricCurrencyAndAmount: A number of monetary units specified in an active or a historic currency where the unit of currency is explicit and compliant with ISO 4217.
95#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
96pub struct ActiveOrHistoricCurrencyAndAmount {
97    #[serde(rename = "@Ccy")]
98    pub ccy: String,
99    #[serde(rename = "$value")]
100    pub value: f64,
101}
102
103impl ActiveOrHistoricCurrencyAndAmount {
104    pub fn validate(&self) -> Result<(), ValidationError> {
105        Ok(())
106    }
107}
108
109// AddressType2Code: Address is the address to which delivery is to take place.
110#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
111pub enum AddressType2Code {
112    #[default]
113    #[serde(rename = "ADDR")]
114    CodeADDR,
115    #[serde(rename = "PBOX")]
116    CodePBOX,
117    #[serde(rename = "HOME")]
118    CodeHOME,
119    #[serde(rename = "BIZZ")]
120    CodeBIZZ,
121    #[serde(rename = "MLTO")]
122    CodeMLTO,
123    #[serde(rename = "DLVY")]
124    CodeDLVY,
125}
126
127impl AddressType2Code {
128    pub fn validate(&self) -> Result<(), ValidationError> {
129        Ok(())
130    }
131}
132
133// AddressType3Choice: Type of address expressed as a proprietary code.
134#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
135pub struct AddressType3Choice {
136    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
137    pub cd: Option<AddressType2Code>,
138    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
139    pub prtry: Option<GenericIdentification30>,
140}
141
142impl AddressType3Choice {
143    pub fn validate(&self) -> Result<(), ValidationError> {
144        if let Some(ref val) = self.cd {
145            val.validate()?
146        }
147        if let Some(ref val) = self.prtry {
148            val.validate()?
149        }
150        Ok(())
151    }
152}
153
154// AmountType4Choice: Amount of money to be moved between the debtor and creditor, expressed in the currency of the debtor's account, and the currency in which the amount is to be moved.
155#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
156pub struct AmountType4Choice {
157    #[serde(rename = "InstdAmt", skip_serializing_if = "Option::is_none")]
158    pub instd_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
159    #[serde(rename = "EqvtAmt", skip_serializing_if = "Option::is_none")]
160    pub eqvt_amt: Option<EquivalentAmount2>,
161}
162
163impl AmountType4Choice {
164    pub fn validate(&self) -> Result<(), ValidationError> {
165        if let Some(ref val) = self.instd_amt {
166            val.validate()?
167        }
168        if let Some(ref val) = self.eqvt_amt {
169            val.validate()?
170        }
171        Ok(())
172    }
173}
174
175// Authorisation1Choice: Specifies the authorisation, in a free text form.
176#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
177pub struct Authorisation1Choice {
178    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
179    pub cd: Option<Authorisation1Code>,
180    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
181    pub prtry: Option<String>,
182}
183
184impl Authorisation1Choice {
185    pub fn validate(&self) -> Result<(), ValidationError> {
186        if let Some(ref val) = self.cd {
187            val.validate()?
188        }
189        if let Some(ref val) = self.prtry {
190            if val.chars().count() < 1 {
191                return Err(ValidationError::new(
192                    1001,
193                    "prtry is shorter than the minimum length of 1".to_string(),
194                ));
195            }
196            if val.chars().count() > 128 {
197                return Err(ValidationError::new(
198                    1002,
199                    "prtry exceeds the maximum length of 128".to_string(),
200                ));
201            }
202        }
203        Ok(())
204    }
205}
206
207// Authorisation1Code: Indicates that a file requires all customer transactions to be authorised or approved.
208#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
209pub enum Authorisation1Code {
210    #[default]
211    #[serde(rename = "AUTH")]
212    CodeAUTH,
213    #[serde(rename = "FDET")]
214    CodeFDET,
215    #[serde(rename = "FSUM")]
216    CodeFSUM,
217    #[serde(rename = "ILEV")]
218    CodeILEV,
219}
220
221impl Authorisation1Code {
222    pub fn validate(&self) -> Result<(), ValidationError> {
223        Ok(())
224    }
225}
226
227// BranchAndFinancialInstitutionIdentification6: Identifies a specific branch of a financial institution.
228//
229// Usage: This component should be used in case the identification information in the financial institution component does not provide identification up to branch level.
230#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
231pub struct BranchAndFinancialInstitutionIdentification6 {
232    #[serde(rename = "FinInstnId")]
233    pub fin_instn_id: FinancialInstitutionIdentification18,
234    #[serde(rename = "BrnchId", skip_serializing_if = "Option::is_none")]
235    pub brnch_id: Option<BranchData3>,
236}
237
238impl BranchAndFinancialInstitutionIdentification6 {
239    pub fn validate(&self) -> Result<(), ValidationError> {
240        self.fin_instn_id.validate()?;
241        if let Some(ref val) = self.brnch_id {
242            val.validate()?
243        }
244        Ok(())
245    }
246}
247
248// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
249#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
250pub struct BranchAndFinancialInstitutionIdentification61 {
251    #[serde(rename = "FinInstnId")]
252    pub fin_instn_id: FinancialInstitutionIdentification181,
253}
254
255impl BranchAndFinancialInstitutionIdentification61 {
256    pub fn validate(&self) -> Result<(), ValidationError> {
257        self.fin_instn_id.validate()?;
258        Ok(())
259    }
260}
261
262// BranchAndFinancialInstitutionIdentification62: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
263#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
264pub struct BranchAndFinancialInstitutionIdentification62 {
265    #[serde(rename = "FinInstnId")]
266    pub fin_instn_id: FinancialInstitutionIdentification182,
267}
268
269impl BranchAndFinancialInstitutionIdentification62 {
270    pub fn validate(&self) -> Result<(), ValidationError> {
271        self.fin_instn_id.validate()?;
272        Ok(())
273    }
274}
275
276// BranchAndFinancialInstitutionIdentification63: Identifies a specific branch of a financial institution.
277//
278// Usage: This component should be used in case the identification information in the financial institution component does not provide identification up to branch level.
279#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
280pub struct BranchAndFinancialInstitutionIdentification63 {
281    #[serde(rename = "FinInstnId")]
282    pub fin_instn_id: FinancialInstitutionIdentification182,
283    #[serde(rename = "BrnchId", skip_serializing_if = "Option::is_none")]
284    pub brnch_id: Option<BranchData31>,
285}
286
287impl BranchAndFinancialInstitutionIdentification63 {
288    pub fn validate(&self) -> Result<(), ValidationError> {
289        self.fin_instn_id.validate()?;
290        if let Some(ref val) = self.brnch_id {
291            val.validate()?
292        }
293        Ok(())
294    }
295}
296
297// BranchData3: Information that locates and identifies a specific address, as defined by postal services.
298#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
299pub struct BranchData3 {
300    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
301    pub id: Option<String>,
302    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
303    pub lei: Option<String>,
304    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
305    pub nm: Option<String>,
306    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
307    pub pstl_adr: Option<PostalAddress24>,
308}
309
310impl BranchData3 {
311    pub fn validate(&self) -> Result<(), ValidationError> {
312        if let Some(ref val) = self.id {
313            if val.chars().count() < 1 {
314                return Err(ValidationError::new(
315                    1001,
316                    "id is shorter than the minimum length of 1".to_string(),
317                ));
318            }
319            if val.chars().count() > 35 {
320                return Err(ValidationError::new(
321                    1002,
322                    "id exceeds the maximum length of 35".to_string(),
323                ));
324            }
325        }
326        if let Some(ref val) = self.lei {
327            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
328            if !pattern.is_match(val) {
329                return Err(ValidationError::new(
330                    1005,
331                    "lei does not match the required pattern".to_string(),
332                ));
333            }
334        }
335        if let Some(ref val) = self.nm {
336            if val.chars().count() < 1 {
337                return Err(ValidationError::new(
338                    1001,
339                    "nm is shorter than the minimum length of 1".to_string(),
340                ));
341            }
342            if val.chars().count() > 140 {
343                return Err(ValidationError::new(
344                    1002,
345                    "nm exceeds the maximum length of 140".to_string(),
346                ));
347            }
348        }
349        if let Some(ref val) = self.pstl_adr {
350            val.validate()?
351        }
352        Ok(())
353    }
354}
355
356// BranchData31: Unique and unambiguous identification of a branch of a financial institution.
357#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
358pub struct BranchData31 {
359    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
360    pub id: Option<String>,
361}
362
363impl BranchData31 {
364    pub fn validate(&self) -> Result<(), ValidationError> {
365        if let Some(ref val) = self.id {
366            if val.chars().count() < 1 {
367                return Err(ValidationError::new(
368                    1001,
369                    "id is shorter than the minimum length of 1".to_string(),
370                ));
371            }
372            if val.chars().count() > 35 {
373                return Err(ValidationError::new(
374                    1002,
375                    "id exceeds the maximum length of 35".to_string(),
376                ));
377            }
378        }
379        Ok(())
380    }
381}
382
383// CashAccount38: Specifies an alternate assumed name for the identification of the account.
384#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
385pub struct CashAccount38 {
386    #[serde(rename = "Id")]
387    pub id: AccountIdentification4Choice,
388    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
389    pub tp: Option<CashAccountType2Choice>,
390    #[serde(rename = "Ccy", skip_serializing_if = "Option::is_none")]
391    pub ccy: Option<String>,
392    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
393    pub nm: Option<String>,
394    #[serde(rename = "Prxy", skip_serializing_if = "Option::is_none")]
395    pub prxy: Option<ProxyAccountIdentification1>,
396}
397
398impl CashAccount38 {
399    pub fn validate(&self) -> Result<(), ValidationError> {
400        self.id.validate()?;
401        if let Some(ref val) = self.tp {
402            val.validate()?
403        }
404        if let Some(ref val) = self.ccy {
405            let pattern = Regex::new("[A-Z]{3,3}").unwrap();
406            if !pattern.is_match(val) {
407                return Err(ValidationError::new(
408                    1005,
409                    "ccy does not match the required pattern".to_string(),
410                ));
411            }
412        }
413        if let Some(ref val) = self.nm {
414            if val.chars().count() < 1 {
415                return Err(ValidationError::new(
416                    1001,
417                    "nm is shorter than the minimum length of 1".to_string(),
418                ));
419            }
420            if val.chars().count() > 70 {
421                return Err(ValidationError::new(
422                    1002,
423                    "nm exceeds the maximum length of 70".to_string(),
424                ));
425            }
426        }
427        if let Some(ref val) = self.prxy {
428            val.validate()?
429        }
430        Ok(())
431    }
432}
433
434// CashAccountType2Choice: Nature or use of the account in a proprietary form.
435#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
436pub struct CashAccountType2Choice {
437    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
438    pub cd: Option<String>,
439    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
440    pub prtry: Option<String>,
441}
442
443impl CashAccountType2Choice {
444    pub fn validate(&self) -> Result<(), ValidationError> {
445        if let Some(ref val) = self.cd {
446            if val.chars().count() < 1 {
447                return Err(ValidationError::new(
448                    1001,
449                    "cd is shorter than the minimum length of 1".to_string(),
450                ));
451            }
452            if val.chars().count() > 4 {
453                return Err(ValidationError::new(
454                    1002,
455                    "cd exceeds the maximum length of 4".to_string(),
456                ));
457            }
458        }
459        if let Some(ref val) = self.prtry {
460            if val.chars().count() < 1 {
461                return Err(ValidationError::new(
462                    1001,
463                    "prtry is shorter than the minimum length of 1".to_string(),
464                ));
465            }
466            if val.chars().count() > 35 {
467                return Err(ValidationError::new(
468                    1002,
469                    "prtry exceeds the maximum length of 35".to_string(),
470                ));
471            }
472        }
473        Ok(())
474    }
475}
476
477// CategoryPurpose1Choice: Category purpose, in a proprietary form.
478#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
479pub struct CategoryPurpose1Choice {
480    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
481    pub cd: Option<String>,
482    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
483    pub prtry: Option<String>,
484}
485
486impl CategoryPurpose1Choice {
487    pub fn validate(&self) -> Result<(), ValidationError> {
488        if let Some(ref val) = self.cd {
489            if val.chars().count() < 1 {
490                return Err(ValidationError::new(
491                    1001,
492                    "cd is shorter than the minimum length of 1".to_string(),
493                ));
494            }
495            if val.chars().count() > 4 {
496                return Err(ValidationError::new(
497                    1002,
498                    "cd exceeds the maximum length of 4".to_string(),
499                ));
500            }
501        }
502        if let Some(ref val) = self.prtry {
503            if val.chars().count() < 1 {
504                return Err(ValidationError::new(
505                    1001,
506                    "prtry is shorter than the minimum length of 1".to_string(),
507                ));
508            }
509            if val.chars().count() > 35 {
510                return Err(ValidationError::new(
511                    1002,
512                    "prtry exceeds the maximum length of 35".to_string(),
513                ));
514            }
515        }
516        Ok(())
517    }
518}
519
520// ChargeBearerType1Code__1: In a credit transfer context, means that transaction charges on the sender side are to be borne by the debtor, transaction charges on the receiver side are to be borne by the creditor. In a direct debit context, means that transaction charges on the sender side are to be borne by the creditor, transaction charges on the receiver side are to be borne by the debtor.
521#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
522pub enum ChargeBearerType1Code1 {
523    #[default]
524    #[serde(rename = "DEBT")]
525    CodeDEBT,
526    #[serde(rename = "CRED")]
527    CodeCRED,
528    #[serde(rename = "SHAR")]
529    CodeSHAR,
530}
531
532impl ChargeBearerType1Code1 {
533    pub fn validate(&self) -> Result<(), ValidationError> {
534        Ok(())
535    }
536}
537
538// Cheque111: Signature to be used by the cheque servicer on a specific cheque to be printed.
539#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
540pub struct Cheque111 {
541    #[serde(rename = "ChqTp", skip_serializing_if = "Option::is_none")]
542    pub chq_tp: Option<ChequeType2Code1>,
543    #[serde(rename = "ChqNb", skip_serializing_if = "Option::is_none")]
544    pub chq_nb: Option<String>,
545    #[serde(rename = "ChqFr", skip_serializing_if = "Option::is_none")]
546    pub chq_fr: Option<NameAndAddress161>,
547    #[serde(rename = "DlvryMtd", skip_serializing_if = "Option::is_none")]
548    pub dlvry_mtd: Option<ChequeDeliveryMethod1Choice>,
549    #[serde(rename = "DlvrTo", skip_serializing_if = "Option::is_none")]
550    pub dlvr_to: Option<NameAndAddress161>,
551    #[serde(rename = "InstrPrty", skip_serializing_if = "Option::is_none")]
552    pub instr_prty: Option<Priority2Code>,
553    #[serde(rename = "ChqMtrtyDt", skip_serializing_if = "Option::is_none")]
554    pub chq_mtrty_dt: Option<String>,
555    #[serde(rename = "FrmsCd", skip_serializing_if = "Option::is_none")]
556    pub frms_cd: Option<String>,
557    #[serde(rename = "MemoFld", skip_serializing_if = "Option::is_none")]
558    pub memo_fld: Option<Vec<String>>,
559    #[serde(rename = "RgnlClrZone", skip_serializing_if = "Option::is_none")]
560    pub rgnl_clr_zone: Option<String>,
561    #[serde(rename = "PrtLctn", skip_serializing_if = "Option::is_none")]
562    pub prt_lctn: Option<String>,
563    #[serde(rename = "Sgntr", skip_serializing_if = "Option::is_none")]
564    pub sgntr: Option<Vec<String>>,
565}
566
567impl Cheque111 {
568    pub fn validate(&self) -> Result<(), ValidationError> {
569        if let Some(ref val) = self.chq_tp {
570            val.validate()?
571        }
572        if let Some(ref val) = self.chq_nb {
573            if val.chars().count() < 1 {
574                return Err(ValidationError::new(
575                    1001,
576                    "chq_nb is shorter than the minimum length of 1".to_string(),
577                ));
578            }
579            if val.chars().count() > 35 {
580                return Err(ValidationError::new(
581                    1002,
582                    "chq_nb exceeds the maximum length of 35".to_string(),
583                ));
584            }
585        }
586        if let Some(ref val) = self.chq_fr {
587            val.validate()?
588        }
589        if let Some(ref val) = self.dlvry_mtd {
590            val.validate()?
591        }
592        if let Some(ref val) = self.dlvr_to {
593            val.validate()?
594        }
595        if let Some(ref val) = self.instr_prty {
596            val.validate()?
597        }
598        if let Some(ref val) = self.frms_cd {
599            if val.chars().count() < 1 {
600                return Err(ValidationError::new(
601                    1001,
602                    "frms_cd is shorter than the minimum length of 1".to_string(),
603                ));
604            }
605            if val.chars().count() > 35 {
606                return Err(ValidationError::new(
607                    1002,
608                    "frms_cd exceeds the maximum length of 35".to_string(),
609                ));
610            }
611        }
612        if let Some(ref vec) = self.memo_fld {
613            for item in vec {
614                if item.chars().count() < 1 {
615                    return Err(ValidationError::new(
616                        1001,
617                        "memo_fld is shorter than the minimum length of 1".to_string(),
618                    ));
619                }
620                if item.chars().count() > 35 {
621                    return Err(ValidationError::new(
622                        1002,
623                        "memo_fld exceeds the maximum length of 35".to_string(),
624                    ));
625                }
626            }
627        }
628        if let Some(ref val) = self.rgnl_clr_zone {
629            if val.chars().count() < 1 {
630                return Err(ValidationError::new(
631                    1001,
632                    "rgnl_clr_zone is shorter than the minimum length of 1".to_string(),
633                ));
634            }
635            if val.chars().count() > 35 {
636                return Err(ValidationError::new(
637                    1002,
638                    "rgnl_clr_zone exceeds the maximum length of 35".to_string(),
639                ));
640            }
641        }
642        if let Some(ref val) = self.prt_lctn {
643            if val.chars().count() < 1 {
644                return Err(ValidationError::new(
645                    1001,
646                    "prt_lctn is shorter than the minimum length of 1".to_string(),
647                ));
648            }
649            if val.chars().count() > 35 {
650                return Err(ValidationError::new(
651                    1002,
652                    "prt_lctn exceeds the maximum length of 35".to_string(),
653                ));
654            }
655        }
656        if let Some(ref vec) = self.sgntr {
657            for item in vec {
658                if item.chars().count() < 1 {
659                    return Err(ValidationError::new(
660                        1001,
661                        "sgntr is shorter than the minimum length of 1".to_string(),
662                    ));
663                }
664                if item.chars().count() > 70 {
665                    return Err(ValidationError::new(
666                        1002,
667                        "sgntr exceeds the maximum length of 70".to_string(),
668                    ));
669                }
670            }
671        }
672        Ok(())
673    }
674}
675
676// ChequeDelivery1Code: Cheque is to be sent through registered mail services to creditor agent.
677#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
678pub enum ChequeDelivery1Code {
679    #[default]
680    #[serde(rename = "MLDB")]
681    CodeMLDB,
682    #[serde(rename = "MLCD")]
683    CodeMLCD,
684    #[serde(rename = "MLFA")]
685    CodeMLFA,
686    #[serde(rename = "CRDB")]
687    CodeCRDB,
688    #[serde(rename = "CRCD")]
689    CodeCRCD,
690    #[serde(rename = "CRFA")]
691    CodeCRFA,
692    #[serde(rename = "PUDB")]
693    CodePUDB,
694    #[serde(rename = "PUCD")]
695    CodePUCD,
696    #[serde(rename = "PUFA")]
697    CodePUFA,
698    #[serde(rename = "RGDB")]
699    CodeRGDB,
700    #[serde(rename = "RGCD")]
701    CodeRGCD,
702    #[serde(rename = "RGFA")]
703    CodeRGFA,
704}
705
706impl ChequeDelivery1Code {
707    pub fn validate(&self) -> Result<(), ValidationError> {
708        Ok(())
709    }
710}
711
712// ChequeDeliveryMethod1Choice: Specifies a proprietary delivery method of the cheque by the debtor's agent.
713#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
714pub struct ChequeDeliveryMethod1Choice {
715    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
716    pub cd: Option<ChequeDelivery1Code>,
717    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
718    pub prtry: Option<String>,
719}
720
721impl ChequeDeliveryMethod1Choice {
722    pub fn validate(&self) -> Result<(), ValidationError> {
723        if let Some(ref val) = self.cd {
724            val.validate()?
725        }
726        if let Some(ref val) = self.prtry {
727            if val.chars().count() < 1 {
728                return Err(ValidationError::new(
729                    1001,
730                    "prtry is shorter than the minimum length of 1".to_string(),
731                ));
732            }
733            if val.chars().count() > 35 {
734                return Err(ValidationError::new(
735                    1002,
736                    "prtry exceeds the maximum length of 35".to_string(),
737                ));
738            }
739        }
740        Ok(())
741    }
742}
743
744// ChequeType2Code__1: A guaranteed bank cheque with a future value date (do not pay before], which in commercial terms is a 'negotiatable instrument': the beneficiary can receive early payment from any bank under subtraction of a discount. The ordering customer's account is debited on value date.
745#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
746pub enum ChequeType2Code1 {
747    #[default]
748    #[serde(rename = "CCHQ")]
749    CodeCCHQ,
750    #[serde(rename = "BCHQ")]
751    CodeBCHQ,
752    #[serde(rename = "DRFT")]
753    CodeDRFT,
754}
755
756impl ChequeType2Code1 {
757    pub fn validate(&self) -> Result<(), ValidationError> {
758        Ok(())
759    }
760}
761
762// ClearingSystemIdentification2Choice: Identification code for a clearing system, that has not yet been identified in the list of clearing systems.
763#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
764pub struct ClearingSystemIdentification2Choice {
765    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
766    pub cd: Option<String>,
767    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
768    pub prtry: Option<String>,
769}
770
771impl ClearingSystemIdentification2Choice {
772    pub fn validate(&self) -> Result<(), ValidationError> {
773        if let Some(ref val) = self.cd {
774            if val.chars().count() < 1 {
775                return Err(ValidationError::new(
776                    1001,
777                    "cd is shorter than the minimum length of 1".to_string(),
778                ));
779            }
780            if val.chars().count() > 5 {
781                return Err(ValidationError::new(
782                    1002,
783                    "cd exceeds the maximum length of 5".to_string(),
784                ));
785            }
786        }
787        if let Some(ref val) = self.prtry {
788            if val.chars().count() < 1 {
789                return Err(ValidationError::new(
790                    1001,
791                    "prtry is shorter than the minimum length of 1".to_string(),
792                ));
793            }
794            if val.chars().count() > 35 {
795                return Err(ValidationError::new(
796                    1002,
797                    "prtry exceeds the maximum length of 35".to_string(),
798                ));
799            }
800        }
801        Ok(())
802    }
803}
804
805// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
806#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
807pub struct ClearingSystemIdentification2Choice1 {
808    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
809    pub cd: Option<String>,
810}
811
812impl ClearingSystemIdentification2Choice1 {
813    pub fn validate(&self) -> Result<(), ValidationError> {
814        if let Some(ref val) = self.cd {
815            if val.chars().count() < 1 {
816                return Err(ValidationError::new(
817                    1001,
818                    "cd is shorter than the minimum length of 1".to_string(),
819                ));
820            }
821            if val.chars().count() > 5 {
822                return Err(ValidationError::new(
823                    1002,
824                    "cd exceeds the maximum length of 5".to_string(),
825                ));
826            }
827        }
828        Ok(())
829    }
830}
831
832// ClearingSystemMemberIdentification2: Identification of a member of a clearing system.
833#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
834pub struct ClearingSystemMemberIdentification2 {
835    #[serde(rename = "ClrSysId", skip_serializing_if = "Option::is_none")]
836    pub clr_sys_id: Option<ClearingSystemIdentification2Choice>,
837    #[serde(rename = "MmbId")]
838    pub mmb_id: String,
839}
840
841impl ClearingSystemMemberIdentification2 {
842    pub fn validate(&self) -> Result<(), ValidationError> {
843        if let Some(ref val) = self.clr_sys_id {
844            val.validate()?
845        }
846        if self.mmb_id.chars().count() < 1 {
847            return Err(ValidationError::new(
848                1001,
849                "mmb_id is shorter than the minimum length of 1".to_string(),
850            ));
851        }
852        if self.mmb_id.chars().count() > 35 {
853            return Err(ValidationError::new(
854                1002,
855                "mmb_id exceeds the maximum length of 35".to_string(),
856            ));
857        }
858        Ok(())
859    }
860}
861
862// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
863#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
864pub struct ClearingSystemMemberIdentification21 {
865    #[serde(rename = "ClrSysId")]
866    pub clr_sys_id: ClearingSystemIdentification2Choice1,
867    #[serde(rename = "MmbId")]
868    pub mmb_id: String,
869}
870
871impl ClearingSystemMemberIdentification21 {
872    pub fn validate(&self) -> Result<(), ValidationError> {
873        self.clr_sys_id.validate()?;
874        if self.mmb_id.chars().count() < 1 {
875            return Err(ValidationError::new(
876                1001,
877                "mmb_id is shorter than the minimum length of 1".to_string(),
878            ));
879        }
880        if self.mmb_id.chars().count() > 35 {
881            return Err(ValidationError::new(
882                1002,
883                "mmb_id exceeds the maximum length of 35".to_string(),
884            ));
885        }
886        Ok(())
887    }
888}
889
890// Contact4: Preferred method used to reach the contact.
891#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
892pub struct Contact4 {
893    #[serde(rename = "NmPrfx", skip_serializing_if = "Option::is_none")]
894    pub nm_prfx: Option<NamePrefix2Code>,
895    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
896    pub nm: Option<String>,
897    #[serde(rename = "PhneNb", skip_serializing_if = "Option::is_none")]
898    pub phne_nb: Option<String>,
899    #[serde(rename = "MobNb", skip_serializing_if = "Option::is_none")]
900    pub mob_nb: Option<String>,
901    #[serde(rename = "FaxNb", skip_serializing_if = "Option::is_none")]
902    pub fax_nb: Option<String>,
903    #[serde(rename = "EmailAdr", skip_serializing_if = "Option::is_none")]
904    pub email_adr: Option<String>,
905    #[serde(rename = "EmailPurp", skip_serializing_if = "Option::is_none")]
906    pub email_purp: Option<String>,
907    #[serde(rename = "JobTitl", skip_serializing_if = "Option::is_none")]
908    pub job_titl: Option<String>,
909    #[serde(rename = "Rspnsblty", skip_serializing_if = "Option::is_none")]
910    pub rspnsblty: Option<String>,
911    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
912    pub dept: Option<String>,
913    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
914    pub othr: Option<Vec<OtherContact1>>,
915    #[serde(rename = "PrefrdMtd", skip_serializing_if = "Option::is_none")]
916    pub prefrd_mtd: Option<PreferredContactMethod1Code>,
917}
918
919impl Contact4 {
920    pub fn validate(&self) -> Result<(), ValidationError> {
921        if let Some(ref val) = self.nm_prfx {
922            val.validate()?
923        }
924        if let Some(ref val) = self.nm {
925            if val.chars().count() < 1 {
926                return Err(ValidationError::new(
927                    1001,
928                    "nm is shorter than the minimum length of 1".to_string(),
929                ));
930            }
931            if val.chars().count() > 140 {
932                return Err(ValidationError::new(
933                    1002,
934                    "nm exceeds the maximum length of 140".to_string(),
935                ));
936            }
937        }
938        if let Some(ref val) = self.phne_nb {
939            let pattern = Regex::new("\\+[0-9]{1,3}-[0-9()+\\-]{1,30}").unwrap();
940            if !pattern.is_match(val) {
941                return Err(ValidationError::new(
942                    1005,
943                    "phne_nb does not match the required pattern".to_string(),
944                ));
945            }
946        }
947        if let Some(ref val) = self.mob_nb {
948            let pattern = Regex::new("\\+[0-9]{1,3}-[0-9()+\\-]{1,30}").unwrap();
949            if !pattern.is_match(val) {
950                return Err(ValidationError::new(
951                    1005,
952                    "mob_nb does not match the required pattern".to_string(),
953                ));
954            }
955        }
956        if let Some(ref val) = self.fax_nb {
957            let pattern = Regex::new("\\+[0-9]{1,3}-[0-9()+\\-]{1,30}").unwrap();
958            if !pattern.is_match(val) {
959                return Err(ValidationError::new(
960                    1005,
961                    "fax_nb does not match the required pattern".to_string(),
962                ));
963            }
964        }
965        if let Some(ref val) = self.email_adr {
966            if val.chars().count() < 1 {
967                return Err(ValidationError::new(
968                    1001,
969                    "email_adr is shorter than the minimum length of 1".to_string(),
970                ));
971            }
972            if val.chars().count() > 2048 {
973                return Err(ValidationError::new(
974                    1002,
975                    "email_adr exceeds the maximum length of 2048".to_string(),
976                ));
977            }
978        }
979        if let Some(ref val) = self.email_purp {
980            if val.chars().count() < 1 {
981                return Err(ValidationError::new(
982                    1001,
983                    "email_purp is shorter than the minimum length of 1".to_string(),
984                ));
985            }
986            if val.chars().count() > 35 {
987                return Err(ValidationError::new(
988                    1002,
989                    "email_purp exceeds the maximum length of 35".to_string(),
990                ));
991            }
992        }
993        if let Some(ref val) = self.job_titl {
994            if val.chars().count() < 1 {
995                return Err(ValidationError::new(
996                    1001,
997                    "job_titl is shorter than the minimum length of 1".to_string(),
998                ));
999            }
1000            if val.chars().count() > 35 {
1001                return Err(ValidationError::new(
1002                    1002,
1003                    "job_titl exceeds the maximum length of 35".to_string(),
1004                ));
1005            }
1006        }
1007        if let Some(ref val) = self.rspnsblty {
1008            if val.chars().count() < 1 {
1009                return Err(ValidationError::new(
1010                    1001,
1011                    "rspnsblty is shorter than the minimum length of 1".to_string(),
1012                ));
1013            }
1014            if val.chars().count() > 35 {
1015                return Err(ValidationError::new(
1016                    1002,
1017                    "rspnsblty exceeds the maximum length of 35".to_string(),
1018                ));
1019            }
1020        }
1021        if let Some(ref val) = self.dept {
1022            if val.chars().count() < 1 {
1023                return Err(ValidationError::new(
1024                    1001,
1025                    "dept is shorter than the minimum length of 1".to_string(),
1026                ));
1027            }
1028            if val.chars().count() > 70 {
1029                return Err(ValidationError::new(
1030                    1002,
1031                    "dept exceeds the maximum length of 70".to_string(),
1032                ));
1033            }
1034        }
1035        if let Some(ref vec) = self.othr {
1036            for item in vec {
1037                item.validate()?
1038            }
1039        }
1040        if let Some(ref val) = self.prefrd_mtd {
1041            val.validate()?
1042        }
1043        Ok(())
1044    }
1045}
1046
1047// CreditDebitCode: Operation is a decrease.
1048#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1049pub enum CreditDebitCode {
1050    #[default]
1051    #[serde(rename = "CRDT")]
1052    CodeCRDT,
1053    #[serde(rename = "DBIT")]
1054    CodeDBIT,
1055}
1056
1057impl CreditDebitCode {
1058    pub fn validate(&self) -> Result<(), ValidationError> {
1059        Ok(())
1060    }
1061}
1062
1063// CreditTransferTransaction341: Information supplied to enable the matching of an entry with the items that the transfer is intended to settle, such as commercial invoices in an accounts' receivable system.
1064#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1065pub struct CreditTransferTransaction341 {
1066    #[serde(rename = "PmtId")]
1067    pub pmt_id: PaymentIdentification61,
1068    #[serde(rename = "PmtTpInf", skip_serializing_if = "Option::is_none")]
1069    pub pmt_tp_inf: Option<PaymentTypeInformation261>,
1070    #[serde(rename = "Amt")]
1071    pub amt: AmountType4Choice,
1072    #[serde(rename = "XchgRateInf", skip_serializing_if = "Option::is_none")]
1073    pub xchg_rate_inf: Option<ExchangeRate1>,
1074    #[serde(rename = "ChrgBr", skip_serializing_if = "Option::is_none")]
1075    pub chrg_br: Option<ChargeBearerType1Code1>,
1076    #[serde(rename = "ChqInstr", skip_serializing_if = "Option::is_none")]
1077    pub chq_instr: Option<Cheque111>,
1078    #[serde(rename = "UltmtDbtr", skip_serializing_if = "Option::is_none")]
1079    pub ultmt_dbtr: Option<PartyIdentification1353>,
1080    #[serde(rename = "IntrmyAgt1", skip_serializing_if = "Option::is_none")]
1081    pub intrmy_agt1: Option<BranchAndFinancialInstitutionIdentification62>,
1082    #[serde(rename = "IntrmyAgt1Acct", skip_serializing_if = "Option::is_none")]
1083    pub intrmy_agt1_acct: Option<CashAccount38>,
1084    #[serde(rename = "IntrmyAgt2", skip_serializing_if = "Option::is_none")]
1085    pub intrmy_agt2: Option<BranchAndFinancialInstitutionIdentification62>,
1086    #[serde(rename = "IntrmyAgt2Acct", skip_serializing_if = "Option::is_none")]
1087    pub intrmy_agt2_acct: Option<CashAccount38>,
1088    #[serde(rename = "IntrmyAgt3", skip_serializing_if = "Option::is_none")]
1089    pub intrmy_agt3: Option<BranchAndFinancialInstitutionIdentification62>,
1090    #[serde(rename = "IntrmyAgt3Acct", skip_serializing_if = "Option::is_none")]
1091    pub intrmy_agt3_acct: Option<CashAccount38>,
1092    #[serde(rename = "CdtrAgt", skip_serializing_if = "Option::is_none")]
1093    pub cdtr_agt: Option<BranchAndFinancialInstitutionIdentification63>,
1094    #[serde(rename = "CdtrAgtAcct", skip_serializing_if = "Option::is_none")]
1095    pub cdtr_agt_acct: Option<CashAccount38>,
1096    #[serde(rename = "Cdtr")]
1097    pub cdtr: PartyIdentification1354,
1098    #[serde(rename = "CdtrAcct", skip_serializing_if = "Option::is_none")]
1099    pub cdtr_acct: Option<CashAccount38>,
1100    #[serde(rename = "UltmtCdtr", skip_serializing_if = "Option::is_none")]
1101    pub ultmt_cdtr: Option<PartyIdentification1353>,
1102    #[serde(rename = "InstrForCdtrAgt", skip_serializing_if = "Option::is_none")]
1103    pub instr_for_cdtr_agt: Option<Vec<InstructionForCreditorAgent1>>,
1104    #[serde(rename = "InstrForDbtrAgt", skip_serializing_if = "Option::is_none")]
1105    pub instr_for_dbtr_agt: Option<String>,
1106    #[serde(rename = "Purp", skip_serializing_if = "Option::is_none")]
1107    pub purp: Option<Purpose2Choice>,
1108    #[serde(rename = "RgltryRptg", skip_serializing_if = "Option::is_none")]
1109    pub rgltry_rptg: Option<Vec<RegulatoryReporting3>>,
1110    #[serde(rename = "Tax", skip_serializing_if = "Option::is_none")]
1111    pub tax: Option<TaxInformation8>,
1112    #[serde(rename = "RltdRmtInf", skip_serializing_if = "Option::is_none")]
1113    pub rltd_rmt_inf: Option<Vec<RemittanceLocation71>>,
1114    #[serde(rename = "RmtInf", skip_serializing_if = "Option::is_none")]
1115    pub rmt_inf: Option<RemittanceInformation161>,
1116}
1117
1118impl CreditTransferTransaction341 {
1119    pub fn validate(&self) -> Result<(), ValidationError> {
1120        self.pmt_id.validate()?;
1121        if let Some(ref val) = self.pmt_tp_inf {
1122            val.validate()?
1123        }
1124        self.amt.validate()?;
1125        if let Some(ref val) = self.xchg_rate_inf {
1126            val.validate()?
1127        }
1128        if let Some(ref val) = self.chrg_br {
1129            val.validate()?
1130        }
1131        if let Some(ref val) = self.chq_instr {
1132            val.validate()?
1133        }
1134        if let Some(ref val) = self.ultmt_dbtr {
1135            val.validate()?
1136        }
1137        if let Some(ref val) = self.intrmy_agt1 {
1138            val.validate()?
1139        }
1140        if let Some(ref val) = self.intrmy_agt1_acct {
1141            val.validate()?
1142        }
1143        if let Some(ref val) = self.intrmy_agt2 {
1144            val.validate()?
1145        }
1146        if let Some(ref val) = self.intrmy_agt2_acct {
1147            val.validate()?
1148        }
1149        if let Some(ref val) = self.intrmy_agt3 {
1150            val.validate()?
1151        }
1152        if let Some(ref val) = self.intrmy_agt3_acct {
1153            val.validate()?
1154        }
1155        if let Some(ref val) = self.cdtr_agt {
1156            val.validate()?
1157        }
1158        if let Some(ref val) = self.cdtr_agt_acct {
1159            val.validate()?
1160        }
1161        self.cdtr.validate()?;
1162        if let Some(ref val) = self.cdtr_acct {
1163            val.validate()?
1164        }
1165        if let Some(ref val) = self.ultmt_cdtr {
1166            val.validate()?
1167        }
1168        if let Some(ref vec) = self.instr_for_cdtr_agt {
1169            for item in vec {
1170                item.validate()?
1171            }
1172        }
1173        if let Some(ref val) = self.instr_for_dbtr_agt {
1174            if val.chars().count() < 1 {
1175                return Err(ValidationError::new(
1176                    1001,
1177                    "instr_for_dbtr_agt is shorter than the minimum length of 1".to_string(),
1178                ));
1179            }
1180            if val.chars().count() > 140 {
1181                return Err(ValidationError::new(
1182                    1002,
1183                    "instr_for_dbtr_agt exceeds the maximum length of 140".to_string(),
1184                ));
1185            }
1186        }
1187        if let Some(ref val) = self.purp {
1188            val.validate()?
1189        }
1190        if let Some(ref vec) = self.rgltry_rptg {
1191            for item in vec {
1192                item.validate()?
1193            }
1194        }
1195        if let Some(ref val) = self.tax {
1196            val.validate()?
1197        }
1198        if let Some(ref vec) = self.rltd_rmt_inf {
1199            for item in vec {
1200                item.validate()?
1201            }
1202        }
1203        if let Some(ref val) = self.rmt_inf {
1204            val.validate()?
1205        }
1206        Ok(())
1207    }
1208}
1209
1210// CreditorReferenceInformation2: Unique reference, as assigned by the creditor, to unambiguously refer to the payment transaction.
1211//
1212// Usage: If available, the initiating party should provide this reference in the structured remittance information, to enable reconciliation by the creditor upon receipt of the amount of money.
1213//
1214// If the business context requires the use of a creditor reference or a payment remit identification, and only one identifier can be passed through the end-to-end chain, the creditor's reference or payment remittance identification should be quoted in the end-to-end transaction identification.
1215#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1216pub struct CreditorReferenceInformation2 {
1217    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
1218    pub tp: Option<CreditorReferenceType2>,
1219    #[serde(rename = "Ref", skip_serializing_if = "Option::is_none")]
1220    pub ref_attr: Option<String>,
1221}
1222
1223impl CreditorReferenceInformation2 {
1224    pub fn validate(&self) -> Result<(), ValidationError> {
1225        if let Some(ref val) = self.tp {
1226            val.validate()?
1227        }
1228        if let Some(ref val) = self.ref_attr {
1229            if val.chars().count() < 1 {
1230                return Err(ValidationError::new(
1231                    1001,
1232                    "ref_attr is shorter than the minimum length of 1".to_string(),
1233                ));
1234            }
1235            if val.chars().count() > 35 {
1236                return Err(ValidationError::new(
1237                    1002,
1238                    "ref_attr exceeds the maximum length of 35".to_string(),
1239                ));
1240            }
1241        }
1242        Ok(())
1243    }
1244}
1245
1246// CreditorReferenceType1Choice: Creditor reference type, in a proprietary form.
1247#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1248pub struct CreditorReferenceType1Choice {
1249    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1250    pub cd: Option<DocumentType3Code>,
1251    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1252    pub prtry: Option<String>,
1253}
1254
1255impl CreditorReferenceType1Choice {
1256    pub fn validate(&self) -> Result<(), ValidationError> {
1257        if let Some(ref val) = self.cd {
1258            val.validate()?
1259        }
1260        if let Some(ref val) = self.prtry {
1261            if val.chars().count() < 1 {
1262                return Err(ValidationError::new(
1263                    1001,
1264                    "prtry is shorter than the minimum length of 1".to_string(),
1265                ));
1266            }
1267            if val.chars().count() > 35 {
1268                return Err(ValidationError::new(
1269                    1002,
1270                    "prtry exceeds the maximum length of 35".to_string(),
1271                ));
1272            }
1273        }
1274        Ok(())
1275    }
1276}
1277
1278// CreditorReferenceType2: Entity that assigns the credit reference type.
1279#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1280pub struct CreditorReferenceType2 {
1281    #[serde(rename = "CdOrPrtry")]
1282    pub cd_or_prtry: CreditorReferenceType1Choice,
1283    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
1284    pub issr: Option<String>,
1285}
1286
1287impl CreditorReferenceType2 {
1288    pub fn validate(&self) -> Result<(), ValidationError> {
1289        self.cd_or_prtry.validate()?;
1290        if let Some(ref val) = self.issr {
1291            if val.chars().count() < 1 {
1292                return Err(ValidationError::new(
1293                    1001,
1294                    "issr is shorter than the minimum length of 1".to_string(),
1295                ));
1296            }
1297            if val.chars().count() > 35 {
1298                return Err(ValidationError::new(
1299                    1002,
1300                    "issr exceeds the maximum length of 35".to_string(),
1301                ));
1302            }
1303        }
1304        Ok(())
1305    }
1306}
1307
1308// CustomerCreditTransferInitiationV09: Set of characteristics that applies to the debit side of the payment transactions included in the credit transfer initiation.
1309#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1310pub struct CustomerCreditTransferInitiationV09 {
1311    #[serde(rename = "GrpHdr")]
1312    pub grp_hdr: GroupHeader851,
1313    #[serde(rename = "PmtInf")]
1314    pub pmt_inf: PaymentInstruction301,
1315}
1316
1317impl CustomerCreditTransferInitiationV09 {
1318    pub fn validate(&self) -> Result<(), ValidationError> {
1319        self.grp_hdr.validate()?;
1320        self.pmt_inf.validate()?;
1321        Ok(())
1322    }
1323}
1324
1325// DateAndDateTime2Choice: Specified date and time.
1326#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1327pub struct DateAndDateTime2Choice {
1328    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
1329    pub dt: Option<String>,
1330    #[serde(rename = "DtTm", skip_serializing_if = "Option::is_none")]
1331    pub dt_tm: Option<String>,
1332}
1333
1334impl DateAndDateTime2Choice {
1335    pub fn validate(&self) -> Result<(), ValidationError> {
1336        Ok(())
1337    }
1338}
1339
1340// DateAndPlaceOfBirth1: Country where a person was born.
1341#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1342pub struct DateAndPlaceOfBirth1 {
1343    #[serde(rename = "BirthDt")]
1344    pub birth_dt: String,
1345    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
1346    pub prvc_of_birth: Option<String>,
1347    #[serde(rename = "CityOfBirth")]
1348    pub city_of_birth: String,
1349    #[serde(rename = "CtryOfBirth")]
1350    pub ctry_of_birth: String,
1351}
1352
1353impl DateAndPlaceOfBirth1 {
1354    pub fn validate(&self) -> Result<(), ValidationError> {
1355        if let Some(ref val) = self.prvc_of_birth {
1356            if val.chars().count() < 1 {
1357                return Err(ValidationError::new(
1358                    1001,
1359                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
1360                ));
1361            }
1362            if val.chars().count() > 35 {
1363                return Err(ValidationError::new(
1364                    1002,
1365                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
1366                ));
1367            }
1368        }
1369        if self.city_of_birth.chars().count() < 1 {
1370            return Err(ValidationError::new(
1371                1001,
1372                "city_of_birth is shorter than the minimum length of 1".to_string(),
1373            ));
1374        }
1375        if self.city_of_birth.chars().count() > 35 {
1376            return Err(ValidationError::new(
1377                1002,
1378                "city_of_birth exceeds the maximum length of 35".to_string(),
1379            ));
1380        }
1381        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1382        if !pattern.is_match(&self.ctry_of_birth) {
1383            return Err(ValidationError::new(
1384                1005,
1385                "ctry_of_birth does not match the required pattern".to_string(),
1386            ));
1387        }
1388        Ok(())
1389    }
1390}
1391
1392// DatePeriod2: End date of the range.
1393#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1394pub struct DatePeriod2 {
1395    #[serde(rename = "FrDt")]
1396    pub fr_dt: String,
1397    #[serde(rename = "ToDt")]
1398    pub to_dt: String,
1399}
1400
1401impl DatePeriod2 {
1402    pub fn validate(&self) -> Result<(), ValidationError> {
1403        Ok(())
1404    }
1405}
1406
1407// DiscountAmountAndType1: Amount of money, which has been typed.
1408#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1409pub struct DiscountAmountAndType1 {
1410    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
1411    pub tp: Option<DiscountAmountType1Choice>,
1412    #[serde(rename = "Amt")]
1413    pub amt: ActiveOrHistoricCurrencyAndAmount,
1414}
1415
1416impl DiscountAmountAndType1 {
1417    pub fn validate(&self) -> Result<(), ValidationError> {
1418        if let Some(ref val) = self.tp {
1419            val.validate()?
1420        }
1421        self.amt.validate()?;
1422        Ok(())
1423    }
1424}
1425
1426// DiscountAmountType1Choice: Specifies the amount type, in a free-text form.
1427#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1428pub struct DiscountAmountType1Choice {
1429    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1430    pub cd: Option<String>,
1431    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1432    pub prtry: Option<String>,
1433}
1434
1435impl DiscountAmountType1Choice {
1436    pub fn validate(&self) -> Result<(), ValidationError> {
1437        if let Some(ref val) = self.cd {
1438            if val.chars().count() < 1 {
1439                return Err(ValidationError::new(
1440                    1001,
1441                    "cd is shorter than the minimum length of 1".to_string(),
1442                ));
1443            }
1444            if val.chars().count() > 4 {
1445                return Err(ValidationError::new(
1446                    1002,
1447                    "cd exceeds the maximum length of 4".to_string(),
1448                ));
1449            }
1450        }
1451        if let Some(ref val) = self.prtry {
1452            if val.chars().count() < 1 {
1453                return Err(ValidationError::new(
1454                    1001,
1455                    "prtry is shorter than the minimum length of 1".to_string(),
1456                ));
1457            }
1458            if val.chars().count() > 35 {
1459                return Err(ValidationError::new(
1460                    1002,
1461                    "prtry exceeds the maximum length of 35".to_string(),
1462                ));
1463            }
1464        }
1465        Ok(())
1466    }
1467}
1468
1469// DocumentAdjustment1: Provides further details on the document adjustment.
1470#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1471pub struct DocumentAdjustment1 {
1472    #[serde(rename = "Amt")]
1473    pub amt: ActiveOrHistoricCurrencyAndAmount,
1474    #[serde(rename = "CdtDbtInd", skip_serializing_if = "Option::is_none")]
1475    pub cdt_dbt_ind: Option<CreditDebitCode>,
1476    #[serde(rename = "Rsn", skip_serializing_if = "Option::is_none")]
1477    pub rsn: Option<String>,
1478    #[serde(rename = "AddtlInf", skip_serializing_if = "Option::is_none")]
1479    pub addtl_inf: Option<String>,
1480}
1481
1482impl DocumentAdjustment1 {
1483    pub fn validate(&self) -> Result<(), ValidationError> {
1484        self.amt.validate()?;
1485        if let Some(ref val) = self.cdt_dbt_ind {
1486            val.validate()?
1487        }
1488        if let Some(ref val) = self.rsn {
1489            if val.chars().count() < 1 {
1490                return Err(ValidationError::new(
1491                    1001,
1492                    "rsn is shorter than the minimum length of 1".to_string(),
1493                ));
1494            }
1495            if val.chars().count() > 4 {
1496                return Err(ValidationError::new(
1497                    1002,
1498                    "rsn exceeds the maximum length of 4".to_string(),
1499                ));
1500            }
1501        }
1502        if let Some(ref val) = self.addtl_inf {
1503            if val.chars().count() < 1 {
1504                return Err(ValidationError::new(
1505                    1001,
1506                    "addtl_inf is shorter than the minimum length of 1".to_string(),
1507                ));
1508            }
1509            if val.chars().count() > 140 {
1510                return Err(ValidationError::new(
1511                    1002,
1512                    "addtl_inf exceeds the maximum length of 140".to_string(),
1513                ));
1514            }
1515        }
1516        Ok(())
1517    }
1518}
1519
1520// DocumentLineIdentification1: Date associated with the referred document line.
1521#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1522pub struct DocumentLineIdentification1 {
1523    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
1524    pub tp: Option<DocumentLineType1>,
1525    #[serde(rename = "Nb", skip_serializing_if = "Option::is_none")]
1526    pub nb: Option<String>,
1527    #[serde(rename = "RltdDt", skip_serializing_if = "Option::is_none")]
1528    pub rltd_dt: Option<String>,
1529}
1530
1531impl DocumentLineIdentification1 {
1532    pub fn validate(&self) -> Result<(), ValidationError> {
1533        if let Some(ref val) = self.tp {
1534            val.validate()?
1535        }
1536        if let Some(ref val) = self.nb {
1537            if val.chars().count() < 1 {
1538                return Err(ValidationError::new(
1539                    1001,
1540                    "nb is shorter than the minimum length of 1".to_string(),
1541                ));
1542            }
1543            if val.chars().count() > 35 {
1544                return Err(ValidationError::new(
1545                    1002,
1546                    "nb exceeds the maximum length of 35".to_string(),
1547                ));
1548            }
1549        }
1550        Ok(())
1551    }
1552}
1553
1554// DocumentLineInformation1: Provides details on the amounts of the document line.
1555#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1556pub struct DocumentLineInformation1 {
1557    #[serde(rename = "Id")]
1558    pub id: Vec<DocumentLineIdentification1>,
1559    #[serde(rename = "Desc", skip_serializing_if = "Option::is_none")]
1560    pub desc: Option<String>,
1561    #[serde(rename = "Amt", skip_serializing_if = "Option::is_none")]
1562    pub amt: Option<RemittanceAmount3>,
1563}
1564
1565impl DocumentLineInformation1 {
1566    pub fn validate(&self) -> Result<(), ValidationError> {
1567        for item in &self.id {
1568            item.validate()?
1569        }
1570        if let Some(ref val) = self.desc {
1571            if val.chars().count() < 1 {
1572                return Err(ValidationError::new(
1573                    1001,
1574                    "desc is shorter than the minimum length of 1".to_string(),
1575                ));
1576            }
1577            if val.chars().count() > 2048 {
1578                return Err(ValidationError::new(
1579                    1002,
1580                    "desc exceeds the maximum length of 2048".to_string(),
1581                ));
1582            }
1583        }
1584        if let Some(ref val) = self.amt {
1585            val.validate()?
1586        }
1587        Ok(())
1588    }
1589}
1590
1591// DocumentLineType1: Identification of the issuer of the reference document line identificationtype.
1592#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1593pub struct DocumentLineType1 {
1594    #[serde(rename = "CdOrPrtry")]
1595    pub cd_or_prtry: DocumentLineType1Choice,
1596    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
1597    pub issr: Option<String>,
1598}
1599
1600impl DocumentLineType1 {
1601    pub fn validate(&self) -> Result<(), ValidationError> {
1602        self.cd_or_prtry.validate()?;
1603        if let Some(ref val) = self.issr {
1604            if val.chars().count() < 1 {
1605                return Err(ValidationError::new(
1606                    1001,
1607                    "issr is shorter than the minimum length of 1".to_string(),
1608                ));
1609            }
1610            if val.chars().count() > 35 {
1611                return Err(ValidationError::new(
1612                    1002,
1613                    "issr exceeds the maximum length of 35".to_string(),
1614                ));
1615            }
1616        }
1617        Ok(())
1618    }
1619}
1620
1621// DocumentLineType1Choice: Proprietary identification of the type of the remittance document.
1622#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1623pub struct DocumentLineType1Choice {
1624    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1625    pub cd: Option<String>,
1626    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1627    pub prtry: Option<String>,
1628}
1629
1630impl DocumentLineType1Choice {
1631    pub fn validate(&self) -> Result<(), ValidationError> {
1632        if let Some(ref val) = self.cd {
1633            if val.chars().count() < 1 {
1634                return Err(ValidationError::new(
1635                    1001,
1636                    "cd is shorter than the minimum length of 1".to_string(),
1637                ));
1638            }
1639            if val.chars().count() > 4 {
1640                return Err(ValidationError::new(
1641                    1002,
1642                    "cd exceeds the maximum length of 4".to_string(),
1643                ));
1644            }
1645        }
1646        if let Some(ref val) = self.prtry {
1647            if val.chars().count() < 1 {
1648                return Err(ValidationError::new(
1649                    1001,
1650                    "prtry is shorter than the minimum length of 1".to_string(),
1651                ));
1652            }
1653            if val.chars().count() > 35 {
1654                return Err(ValidationError::new(
1655                    1002,
1656                    "prtry exceeds the maximum length of 35".to_string(),
1657                ));
1658            }
1659        }
1660        Ok(())
1661    }
1662}
1663
1664// DocumentType3Code: Document is a structured communication reference provided by the creditor to identify the referred transaction.
1665#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1666pub enum DocumentType3Code {
1667    #[default]
1668    #[serde(rename = "RADM")]
1669    CodeRADM,
1670    #[serde(rename = "RPIN")]
1671    CodeRPIN,
1672    #[serde(rename = "FXDR")]
1673    CodeFXDR,
1674    #[serde(rename = "DISP")]
1675    CodeDISP,
1676    #[serde(rename = "PUOR")]
1677    CodePUOR,
1678    #[serde(rename = "SCOR")]
1679    CodeSCOR,
1680}
1681
1682impl DocumentType3Code {
1683    pub fn validate(&self) -> Result<(), ValidationError> {
1684        Ok(())
1685    }
1686}
1687
1688// DocumentType6Code: Document is a purchase order.
1689#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1690pub enum DocumentType6Code {
1691    #[default]
1692    #[serde(rename = "MSIN")]
1693    CodeMSIN,
1694    #[serde(rename = "CNFA")]
1695    CodeCNFA,
1696    #[serde(rename = "DNFA")]
1697    CodeDNFA,
1698    #[serde(rename = "CINV")]
1699    CodeCINV,
1700    #[serde(rename = "CREN")]
1701    CodeCREN,
1702    #[serde(rename = "DEBN")]
1703    CodeDEBN,
1704    #[serde(rename = "HIRI")]
1705    CodeHIRI,
1706    #[serde(rename = "SBIN")]
1707    CodeSBIN,
1708    #[serde(rename = "CMCN")]
1709    CodeCMCN,
1710    #[serde(rename = "SOAC")]
1711    CodeSOAC,
1712    #[serde(rename = "DISP")]
1713    CodeDISP,
1714    #[serde(rename = "BOLD")]
1715    CodeBOLD,
1716    #[serde(rename = "VCHR")]
1717    CodeVCHR,
1718    #[serde(rename = "AROI")]
1719    CodeAROI,
1720    #[serde(rename = "TSUT")]
1721    CodeTSUT,
1722    #[serde(rename = "PUOR")]
1723    CodePUOR,
1724}
1725
1726impl DocumentType6Code {
1727    pub fn validate(&self) -> Result<(), ValidationError> {
1728        Ok(())
1729    }
1730}
1731
1732// EquivalentAmount2: Specifies the currency of the to be transferred amount, which is different from the currency of the debtor's account.
1733#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1734pub struct EquivalentAmount2 {
1735    #[serde(rename = "Amt")]
1736    pub amt: ActiveOrHistoricCurrencyAndAmount,
1737    #[serde(rename = "CcyOfTrf")]
1738    pub ccy_of_trf: String,
1739}
1740
1741impl EquivalentAmount2 {
1742    pub fn validate(&self) -> Result<(), ValidationError> {
1743        self.amt.validate()?;
1744        let pattern = Regex::new("[A-Z]{3,3}").unwrap();
1745        if !pattern.is_match(&self.ccy_of_trf) {
1746            return Err(ValidationError::new(
1747                1005,
1748                "ccy_of_trf does not match the required pattern".to_string(),
1749            ));
1750        }
1751        Ok(())
1752    }
1753}
1754
1755// ExchangeRate1: Unique and unambiguous reference to the foreign exchange contract agreed between the initiating party/creditor and the debtor agent.
1756#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1757pub struct ExchangeRate1 {
1758    #[serde(rename = "UnitCcy", skip_serializing_if = "Option::is_none")]
1759    pub unit_ccy: Option<String>,
1760    #[serde(rename = "XchgRate", skip_serializing_if = "Option::is_none")]
1761    pub xchg_rate: Option<f64>,
1762    #[serde(rename = "RateTp", skip_serializing_if = "Option::is_none")]
1763    pub rate_tp: Option<ExchangeRateType1Code>,
1764    #[serde(rename = "CtrctId", skip_serializing_if = "Option::is_none")]
1765    pub ctrct_id: Option<String>,
1766}
1767
1768impl ExchangeRate1 {
1769    pub fn validate(&self) -> Result<(), ValidationError> {
1770        if let Some(ref val) = self.unit_ccy {
1771            let pattern = Regex::new("[A-Z]{3,3}").unwrap();
1772            if !pattern.is_match(val) {
1773                return Err(ValidationError::new(
1774                    1005,
1775                    "unit_ccy does not match the required pattern".to_string(),
1776                ));
1777            }
1778        }
1779        if let Some(ref val) = self.rate_tp {
1780            val.validate()?
1781        }
1782        if let Some(ref val) = self.ctrct_id {
1783            if val.chars().count() < 1 {
1784                return Err(ValidationError::new(
1785                    1001,
1786                    "ctrct_id is shorter than the minimum length of 1".to_string(),
1787                ));
1788            }
1789            if val.chars().count() > 35 {
1790                return Err(ValidationError::new(
1791                    1002,
1792                    "ctrct_id exceeds the maximum length of 35".to_string(),
1793                ));
1794            }
1795        }
1796        Ok(())
1797    }
1798}
1799
1800// ExchangeRateType1Code: Exchange rate applied is the rate agreed between the parties.
1801#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1802pub enum ExchangeRateType1Code {
1803    #[default]
1804    #[serde(rename = "SPOT")]
1805    CodeSPOT,
1806    #[serde(rename = "SALE")]
1807    CodeSALE,
1808    #[serde(rename = "AGRD")]
1809    CodeAGRD,
1810}
1811
1812impl ExchangeRateType1Code {
1813    pub fn validate(&self) -> Result<(), ValidationError> {
1814        Ok(())
1815    }
1816}
1817
1818// FinancialIdentificationSchemeName1Choice: Name of the identification scheme, in a free text form.
1819#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1820pub struct FinancialIdentificationSchemeName1Choice {
1821    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1822    pub cd: Option<String>,
1823    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1824    pub prtry: Option<String>,
1825}
1826
1827impl FinancialIdentificationSchemeName1Choice {
1828    pub fn validate(&self) -> Result<(), ValidationError> {
1829        if let Some(ref val) = self.cd {
1830            if val.chars().count() < 1 {
1831                return Err(ValidationError::new(
1832                    1001,
1833                    "cd is shorter than the minimum length of 1".to_string(),
1834                ));
1835            }
1836            if val.chars().count() > 4 {
1837                return Err(ValidationError::new(
1838                    1002,
1839                    "cd exceeds the maximum length of 4".to_string(),
1840                ));
1841            }
1842        }
1843        if let Some(ref val) = self.prtry {
1844            if val.chars().count() < 1 {
1845                return Err(ValidationError::new(
1846                    1001,
1847                    "prtry is shorter than the minimum length of 1".to_string(),
1848                ));
1849            }
1850            if val.chars().count() > 35 {
1851                return Err(ValidationError::new(
1852                    1002,
1853                    "prtry exceeds the maximum length of 35".to_string(),
1854                ));
1855            }
1856        }
1857        Ok(())
1858    }
1859}
1860
1861// FinancialInstitutionIdentification18: Unique identification of an agent, as assigned by an institution, using an identification scheme.
1862#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1863pub struct FinancialInstitutionIdentification18 {
1864    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
1865    pub bicfi: Option<String>,
1866    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
1867    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification2>,
1868    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1869    pub lei: Option<String>,
1870    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1871    pub nm: Option<String>,
1872    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1873    pub pstl_adr: Option<PostalAddress24>,
1874    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1875    pub othr: Option<GenericFinancialIdentification1>,
1876}
1877
1878impl FinancialInstitutionIdentification18 {
1879    pub fn validate(&self) -> Result<(), ValidationError> {
1880        if let Some(ref val) = self.bicfi {
1881            let pattern =
1882                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1883            if !pattern.is_match(val) {
1884                return Err(ValidationError::new(
1885                    1005,
1886                    "bicfi does not match the required pattern".to_string(),
1887                ));
1888            }
1889        }
1890        if let Some(ref val) = self.clr_sys_mmb_id {
1891            val.validate()?
1892        }
1893        if let Some(ref val) = self.lei {
1894            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1895            if !pattern.is_match(val) {
1896                return Err(ValidationError::new(
1897                    1005,
1898                    "lei does not match the required pattern".to_string(),
1899                ));
1900            }
1901        }
1902        if let Some(ref val) = self.nm {
1903            if val.chars().count() < 1 {
1904                return Err(ValidationError::new(
1905                    1001,
1906                    "nm is shorter than the minimum length of 1".to_string(),
1907                ));
1908            }
1909            if val.chars().count() > 140 {
1910                return Err(ValidationError::new(
1911                    1002,
1912                    "nm exceeds the maximum length of 140".to_string(),
1913                ));
1914            }
1915        }
1916        if let Some(ref val) = self.pstl_adr {
1917            val.validate()?
1918        }
1919        if let Some(ref val) = self.othr {
1920            val.validate()?
1921        }
1922        Ok(())
1923    }
1924}
1925
1926// FinancialInstitutionIdentification181: Legal entity identifier of the financial institution.
1927#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1928pub struct FinancialInstitutionIdentification181 {
1929    #[serde(rename = "BICFI")]
1930    pub bicfi: String,
1931    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
1932    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
1933    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1934    pub lei: Option<String>,
1935}
1936
1937impl FinancialInstitutionIdentification181 {
1938    pub fn validate(&self) -> Result<(), ValidationError> {
1939        let pattern =
1940            Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1941        if !pattern.is_match(&self.bicfi) {
1942            return Err(ValidationError::new(
1943                1005,
1944                "bicfi does not match the required pattern".to_string(),
1945            ));
1946        }
1947        if let Some(ref val) = self.clr_sys_mmb_id {
1948            val.validate()?
1949        }
1950        if let Some(ref val) = self.lei {
1951            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1952            if !pattern.is_match(val) {
1953                return Err(ValidationError::new(
1954                    1005,
1955                    "lei does not match the required pattern".to_string(),
1956                ));
1957            }
1958        }
1959        Ok(())
1960    }
1961}
1962
1963// FinancialInstitutionIdentification182: Information that locates and identifies a specific address, as defined by postal services.
1964#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1965pub struct FinancialInstitutionIdentification182 {
1966    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
1967    pub bicfi: Option<String>,
1968    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
1969    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
1970    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1971    pub lei: Option<String>,
1972    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1973    pub nm: Option<String>,
1974    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1975    pub pstl_adr: Option<PostalAddress242>,
1976}
1977
1978impl FinancialInstitutionIdentification182 {
1979    pub fn validate(&self) -> Result<(), ValidationError> {
1980        if let Some(ref val) = self.bicfi {
1981            let pattern =
1982                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1983            if !pattern.is_match(val) {
1984                return Err(ValidationError::new(
1985                    1005,
1986                    "bicfi does not match the required pattern".to_string(),
1987                ));
1988            }
1989        }
1990        if let Some(ref val) = self.clr_sys_mmb_id {
1991            val.validate()?
1992        }
1993        if let Some(ref val) = self.lei {
1994            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1995            if !pattern.is_match(val) {
1996                return Err(ValidationError::new(
1997                    1005,
1998                    "lei does not match the required pattern".to_string(),
1999                ));
2000            }
2001        }
2002        if let Some(ref val) = self.nm {
2003            if val.chars().count() < 1 {
2004                return Err(ValidationError::new(
2005                    1001,
2006                    "nm is shorter than the minimum length of 1".to_string(),
2007                ));
2008            }
2009            if val.chars().count() > 140 {
2010                return Err(ValidationError::new(
2011                    1002,
2012                    "nm exceeds the maximum length of 140".to_string(),
2013                ));
2014            }
2015        }
2016        if let Some(ref val) = self.pstl_adr {
2017            val.validate()?
2018        }
2019        Ok(())
2020    }
2021}
2022
2023// Garnishment31: Indicates if the employment of the person to whom the garnishment applies (that is, the ultimate debtor) has been terminated.
2024#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2025pub struct Garnishment31 {
2026    #[serde(rename = "Tp")]
2027    pub tp: GarnishmentType1,
2028    #[serde(rename = "Grnshee", skip_serializing_if = "Option::is_none")]
2029    pub grnshee: Option<PartyIdentification1353>,
2030    #[serde(rename = "GrnshmtAdmstr", skip_serializing_if = "Option::is_none")]
2031    pub grnshmt_admstr: Option<PartyIdentification1353>,
2032    #[serde(rename = "RefNb", skip_serializing_if = "Option::is_none")]
2033    pub ref_nb: Option<String>,
2034    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
2035    pub dt: Option<String>,
2036    #[serde(rename = "RmtdAmt", skip_serializing_if = "Option::is_none")]
2037    pub rmtd_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
2038    #[serde(rename = "FmlyMdclInsrncInd", skip_serializing_if = "Option::is_none")]
2039    pub fmly_mdcl_insrnc_ind: Option<bool>,
2040    #[serde(rename = "MplyeeTermntnInd", skip_serializing_if = "Option::is_none")]
2041    pub mplyee_termntn_ind: Option<bool>,
2042}
2043
2044impl Garnishment31 {
2045    pub fn validate(&self) -> Result<(), ValidationError> {
2046        self.tp.validate()?;
2047        if let Some(ref val) = self.grnshee {
2048            val.validate()?
2049        }
2050        if let Some(ref val) = self.grnshmt_admstr {
2051            val.validate()?
2052        }
2053        if let Some(ref val) = self.ref_nb {
2054            if val.chars().count() < 1 {
2055                return Err(ValidationError::new(
2056                    1001,
2057                    "ref_nb is shorter than the minimum length of 1".to_string(),
2058                ));
2059            }
2060            if val.chars().count() > 140 {
2061                return Err(ValidationError::new(
2062                    1002,
2063                    "ref_nb exceeds the maximum length of 140".to_string(),
2064                ));
2065            }
2066        }
2067        if let Some(ref val) = self.rmtd_amt {
2068            val.validate()?
2069        }
2070        Ok(())
2071    }
2072}
2073
2074// GarnishmentType1: Identification of the issuer of the garnishment type.
2075#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2076pub struct GarnishmentType1 {
2077    #[serde(rename = "CdOrPrtry")]
2078    pub cd_or_prtry: GarnishmentType1Choice,
2079    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2080    pub issr: Option<String>,
2081}
2082
2083impl GarnishmentType1 {
2084    pub fn validate(&self) -> Result<(), ValidationError> {
2085        self.cd_or_prtry.validate()?;
2086        if let Some(ref val) = self.issr {
2087            if val.chars().count() < 1 {
2088                return Err(ValidationError::new(
2089                    1001,
2090                    "issr is shorter than the minimum length of 1".to_string(),
2091                ));
2092            }
2093            if val.chars().count() > 35 {
2094                return Err(ValidationError::new(
2095                    1002,
2096                    "issr exceeds the maximum length of 35".to_string(),
2097                ));
2098            }
2099        }
2100        Ok(())
2101    }
2102}
2103
2104// GarnishmentType1Choice: Proprietary identification of the type of garnishment.
2105#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2106pub struct GarnishmentType1Choice {
2107    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2108    pub cd: Option<String>,
2109    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2110    pub prtry: Option<String>,
2111}
2112
2113impl GarnishmentType1Choice {
2114    pub fn validate(&self) -> Result<(), ValidationError> {
2115        if let Some(ref val) = self.cd {
2116            if val.chars().count() < 1 {
2117                return Err(ValidationError::new(
2118                    1001,
2119                    "cd is shorter than the minimum length of 1".to_string(),
2120                ));
2121            }
2122            if val.chars().count() > 4 {
2123                return Err(ValidationError::new(
2124                    1002,
2125                    "cd exceeds the maximum length of 4".to_string(),
2126                ));
2127            }
2128        }
2129        if let Some(ref val) = self.prtry {
2130            if val.chars().count() < 1 {
2131                return Err(ValidationError::new(
2132                    1001,
2133                    "prtry is shorter than the minimum length of 1".to_string(),
2134                ));
2135            }
2136            if val.chars().count() > 35 {
2137                return Err(ValidationError::new(
2138                    1002,
2139                    "prtry exceeds the maximum length of 35".to_string(),
2140                ));
2141            }
2142        }
2143        Ok(())
2144    }
2145}
2146
2147// GenericAccountIdentification1: Entity that assigns the identification.
2148#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2149pub struct GenericAccountIdentification1 {
2150    #[serde(rename = "Id")]
2151    pub id: String,
2152    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2153    pub schme_nm: Option<AccountSchemeName1Choice>,
2154    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2155    pub issr: Option<String>,
2156}
2157
2158impl GenericAccountIdentification1 {
2159    pub fn validate(&self) -> Result<(), ValidationError> {
2160        if self.id.chars().count() < 1 {
2161            return Err(ValidationError::new(
2162                1001,
2163                "id is shorter than the minimum length of 1".to_string(),
2164            ));
2165        }
2166        if self.id.chars().count() > 34 {
2167            return Err(ValidationError::new(
2168                1002,
2169                "id exceeds the maximum length of 34".to_string(),
2170            ));
2171        }
2172        if let Some(ref val) = self.schme_nm {
2173            val.validate()?
2174        }
2175        if let Some(ref val) = self.issr {
2176            if val.chars().count() < 1 {
2177                return Err(ValidationError::new(
2178                    1001,
2179                    "issr is shorter than the minimum length of 1".to_string(),
2180                ));
2181            }
2182            if val.chars().count() > 35 {
2183                return Err(ValidationError::new(
2184                    1002,
2185                    "issr exceeds the maximum length of 35".to_string(),
2186                ));
2187            }
2188        }
2189        Ok(())
2190    }
2191}
2192
2193// GenericFinancialIdentification1: Entity that assigns the identification.
2194#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2195pub struct GenericFinancialIdentification1 {
2196    #[serde(rename = "Id")]
2197    pub id: String,
2198    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2199    pub schme_nm: Option<FinancialIdentificationSchemeName1Choice>,
2200    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2201    pub issr: Option<String>,
2202}
2203
2204impl GenericFinancialIdentification1 {
2205    pub fn validate(&self) -> Result<(), ValidationError> {
2206        if self.id.chars().count() < 1 {
2207            return Err(ValidationError::new(
2208                1001,
2209                "id is shorter than the minimum length of 1".to_string(),
2210            ));
2211        }
2212        if self.id.chars().count() > 35 {
2213            return Err(ValidationError::new(
2214                1002,
2215                "id exceeds the maximum length of 35".to_string(),
2216            ));
2217        }
2218        if let Some(ref val) = self.schme_nm {
2219            val.validate()?
2220        }
2221        if let Some(ref val) = self.issr {
2222            if val.chars().count() < 1 {
2223                return Err(ValidationError::new(
2224                    1001,
2225                    "issr is shorter than the minimum length of 1".to_string(),
2226                ));
2227            }
2228            if val.chars().count() > 35 {
2229                return Err(ValidationError::new(
2230                    1002,
2231                    "issr exceeds the maximum length of 35".to_string(),
2232                ));
2233            }
2234        }
2235        Ok(())
2236    }
2237}
2238
2239// GenericIdentification30: Short textual description of the scheme.
2240#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2241pub struct GenericIdentification30 {
2242    #[serde(rename = "Id")]
2243    pub id: String,
2244    #[serde(rename = "Issr")]
2245    pub issr: String,
2246    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2247    pub schme_nm: Option<String>,
2248}
2249
2250impl GenericIdentification30 {
2251    pub fn validate(&self) -> Result<(), ValidationError> {
2252        let pattern = Regex::new("[a-zA-Z0-9]{4}").unwrap();
2253        if !pattern.is_match(&self.id) {
2254            return Err(ValidationError::new(
2255                1005,
2256                "id does not match the required pattern".to_string(),
2257            ));
2258        }
2259        if self.issr.chars().count() < 1 {
2260            return Err(ValidationError::new(
2261                1001,
2262                "issr is shorter than the minimum length of 1".to_string(),
2263            ));
2264        }
2265        if self.issr.chars().count() > 35 {
2266            return Err(ValidationError::new(
2267                1002,
2268                "issr exceeds the maximum length of 35".to_string(),
2269            ));
2270        }
2271        if let Some(ref val) = self.schme_nm {
2272            if val.chars().count() < 1 {
2273                return Err(ValidationError::new(
2274                    1001,
2275                    "schme_nm is shorter than the minimum length of 1".to_string(),
2276                ));
2277            }
2278            if val.chars().count() > 35 {
2279                return Err(ValidationError::new(
2280                    1002,
2281                    "schme_nm exceeds the maximum length of 35".to_string(),
2282                ));
2283            }
2284        }
2285        Ok(())
2286    }
2287}
2288
2289// GenericOrganisationIdentification1: Entity that assigns the identification.
2290#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2291pub struct GenericOrganisationIdentification1 {
2292    #[serde(rename = "Id")]
2293    pub id: String,
2294    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2295    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice>,
2296    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2297    pub issr: Option<String>,
2298}
2299
2300impl GenericOrganisationIdentification1 {
2301    pub fn validate(&self) -> Result<(), ValidationError> {
2302        if self.id.chars().count() < 1 {
2303            return Err(ValidationError::new(
2304                1001,
2305                "id is shorter than the minimum length of 1".to_string(),
2306            ));
2307        }
2308        if self.id.chars().count() > 35 {
2309            return Err(ValidationError::new(
2310                1002,
2311                "id exceeds the maximum length of 35".to_string(),
2312            ));
2313        }
2314        if let Some(ref val) = self.schme_nm {
2315            val.validate()?
2316        }
2317        if let Some(ref val) = self.issr {
2318            if val.chars().count() < 1 {
2319                return Err(ValidationError::new(
2320                    1001,
2321                    "issr is shorter than the minimum length of 1".to_string(),
2322                ));
2323            }
2324            if val.chars().count() > 35 {
2325                return Err(ValidationError::new(
2326                    1002,
2327                    "issr exceeds the maximum length of 35".to_string(),
2328                ));
2329            }
2330        }
2331        Ok(())
2332    }
2333}
2334
2335// GenericOrganisationIdentification11: Entity that assigns the identification.
2336#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2337pub struct GenericOrganisationIdentification11 {
2338    #[serde(rename = "Id")]
2339    pub id: String,
2340    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2341    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice1>,
2342    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2343    pub issr: Option<String>,
2344}
2345
2346impl GenericOrganisationIdentification11 {
2347    pub fn validate(&self) -> Result<(), ValidationError> {
2348        if self.id.chars().count() < 1 {
2349            return Err(ValidationError::new(
2350                1001,
2351                "id is shorter than the minimum length of 1".to_string(),
2352            ));
2353        }
2354        if self.id.chars().count() > 35 {
2355            return Err(ValidationError::new(
2356                1002,
2357                "id exceeds the maximum length of 35".to_string(),
2358            ));
2359        }
2360        if let Some(ref val) = self.schme_nm {
2361            val.validate()?
2362        }
2363        if let Some(ref val) = self.issr {
2364            if val.chars().count() < 1 {
2365                return Err(ValidationError::new(
2366                    1001,
2367                    "issr is shorter than the minimum length of 1".to_string(),
2368                ));
2369            }
2370            if val.chars().count() > 35 {
2371                return Err(ValidationError::new(
2372                    1002,
2373                    "issr exceeds the maximum length of 35".to_string(),
2374                ));
2375            }
2376        }
2377        Ok(())
2378    }
2379}
2380
2381// GenericPersonIdentification1: Entity that assigns the identification.
2382#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2383pub struct GenericPersonIdentification1 {
2384    #[serde(rename = "Id")]
2385    pub id: String,
2386    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
2387    pub schme_nm: Option<PersonIdentificationSchemeName1Choice>,
2388    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2389    pub issr: Option<String>,
2390}
2391
2392impl GenericPersonIdentification1 {
2393    pub fn validate(&self) -> Result<(), ValidationError> {
2394        if self.id.chars().count() < 1 {
2395            return Err(ValidationError::new(
2396                1001,
2397                "id is shorter than the minimum length of 1".to_string(),
2398            ));
2399        }
2400        if self.id.chars().count() > 35 {
2401            return Err(ValidationError::new(
2402                1002,
2403                "id exceeds the maximum length of 35".to_string(),
2404            ));
2405        }
2406        if let Some(ref val) = self.schme_nm {
2407            val.validate()?
2408        }
2409        if let Some(ref val) = self.issr {
2410            if val.chars().count() < 1 {
2411                return Err(ValidationError::new(
2412                    1001,
2413                    "issr is shorter than the minimum length of 1".to_string(),
2414                ));
2415            }
2416            if val.chars().count() > 35 {
2417                return Err(ValidationError::new(
2418                    1002,
2419                    "issr exceeds the maximum length of 35".to_string(),
2420                ));
2421            }
2422        }
2423        Ok(())
2424    }
2425}
2426
2427// GenericPersonIdentification11: Entity that assigns the identification.
2428#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2429pub struct GenericPersonIdentification11 {
2430    #[serde(rename = "Id")]
2431    pub id: String,
2432    #[serde(rename = "SchmeNm")]
2433    pub schme_nm: PersonIdentificationSchemeName1Choice1,
2434    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
2435    pub issr: Option<String>,
2436}
2437
2438impl GenericPersonIdentification11 {
2439    pub fn validate(&self) -> Result<(), ValidationError> {
2440        if self.id.chars().count() < 1 {
2441            return Err(ValidationError::new(
2442                1001,
2443                "id is shorter than the minimum length of 1".to_string(),
2444            ));
2445        }
2446        if self.id.chars().count() > 35 {
2447            return Err(ValidationError::new(
2448                1002,
2449                "id exceeds the maximum length of 35".to_string(),
2450            ));
2451        }
2452        self.schme_nm.validate()?;
2453        if let Some(ref val) = self.issr {
2454            if val.chars().count() < 1 {
2455                return Err(ValidationError::new(
2456                    1001,
2457                    "issr is shorter than the minimum length of 1".to_string(),
2458                ));
2459            }
2460            if val.chars().count() > 35 {
2461                return Err(ValidationError::new(
2462                    1002,
2463                    "issr exceeds the maximum length of 35".to_string(),
2464                ));
2465            }
2466        }
2467        Ok(())
2468    }
2469}
2470
2471// GroupHeader851: Financial institution that receives the instruction from the initiating party and forwards it to the next agent in the payment chain for execution.
2472#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2473pub struct GroupHeader851 {
2474    #[serde(rename = "MsgId")]
2475    pub msg_id: String,
2476    #[serde(rename = "CreDtTm")]
2477    pub cre_dt_tm: String,
2478    #[serde(rename = "Authstn", skip_serializing_if = "Option::is_none")]
2479    pub authstn: Option<Vec<Authorisation1Choice>>,
2480    #[serde(rename = "NbOfTxs")]
2481    pub nb_of_txs: Max15NumericTextfixed,
2482    #[serde(rename = "InitgPty")]
2483    pub initg_pty: PartyIdentification1351,
2484    #[serde(rename = "FwdgAgt", skip_serializing_if = "Option::is_none")]
2485    pub fwdg_agt: Option<BranchAndFinancialInstitutionIdentification61>,
2486}
2487
2488impl GroupHeader851 {
2489    pub fn validate(&self) -> Result<(), ValidationError> {
2490        if self.msg_id.chars().count() < 1 {
2491            return Err(ValidationError::new(
2492                1001,
2493                "msg_id is shorter than the minimum length of 1".to_string(),
2494            ));
2495        }
2496        if self.msg_id.chars().count() > 35 {
2497            return Err(ValidationError::new(
2498                1002,
2499                "msg_id exceeds the maximum length of 35".to_string(),
2500            ));
2501        }
2502        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
2503        if !pattern.is_match(&self.msg_id) {
2504            return Err(ValidationError::new(
2505                1005,
2506                "msg_id does not match the required pattern".to_string(),
2507            ));
2508        }
2509        if let Some(ref vec) = self.authstn {
2510            for item in vec {
2511                item.validate()?
2512            }
2513        }
2514        self.nb_of_txs.validate()?;
2515        self.initg_pty.validate()?;
2516        if let Some(ref val) = self.fwdg_agt {
2517            val.validate()?
2518        }
2519        Ok(())
2520    }
2521}
2522
2523// Instruction3Code: Please advise/contact (ultimate) creditor/claimant by the most efficient means of telecommunication.
2524#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2525pub enum Instruction3Code {
2526    #[default]
2527    #[serde(rename = "CHQB")]
2528    CodeCHQB,
2529    #[serde(rename = "HOLD")]
2530    CodeHOLD,
2531    #[serde(rename = "PHOB")]
2532    CodePHOB,
2533    #[serde(rename = "TELB")]
2534    CodeTELB,
2535}
2536
2537impl Instruction3Code {
2538    pub fn validate(&self) -> Result<(), ValidationError> {
2539        Ok(())
2540    }
2541}
2542
2543// InstructionForCreditorAgent1: Further information complementing the coded instruction or instruction to the creditor's agent that is bilaterally agreed or specific to a user community.
2544#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2545pub struct InstructionForCreditorAgent1 {
2546    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2547    pub cd: Option<Instruction3Code>,
2548    #[serde(rename = "InstrInf", skip_serializing_if = "Option::is_none")]
2549    pub instr_inf: Option<String>,
2550}
2551
2552impl InstructionForCreditorAgent1 {
2553    pub fn validate(&self) -> Result<(), ValidationError> {
2554        if let Some(ref val) = self.cd {
2555            val.validate()?
2556        }
2557        if let Some(ref val) = self.instr_inf {
2558            if val.chars().count() < 1 {
2559                return Err(ValidationError::new(
2560                    1001,
2561                    "instr_inf is shorter than the minimum length of 1".to_string(),
2562                ));
2563            }
2564            if val.chars().count() > 140 {
2565                return Err(ValidationError::new(
2566                    1002,
2567                    "instr_inf exceeds the maximum length of 140".to_string(),
2568                ));
2569            }
2570        }
2571        Ok(())
2572    }
2573}
2574
2575// LocalInstrument2Choice: Specifies the local instrument, as a proprietary code.
2576#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2577pub struct LocalInstrument2Choice {
2578    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2579    pub cd: Option<String>,
2580    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2581    pub prtry: Option<String>,
2582}
2583
2584impl LocalInstrument2Choice {
2585    pub fn validate(&self) -> Result<(), ValidationError> {
2586        if let Some(ref val) = self.cd {
2587            if val.chars().count() < 1 {
2588                return Err(ValidationError::new(
2589                    1001,
2590                    "cd is shorter than the minimum length of 1".to_string(),
2591                ));
2592            }
2593            if val.chars().count() > 35 {
2594                return Err(ValidationError::new(
2595                    1002,
2596                    "cd exceeds the maximum length of 35".to_string(),
2597                ));
2598            }
2599        }
2600        if let Some(ref val) = self.prtry {
2601            if val.chars().count() < 1 {
2602                return Err(ValidationError::new(
2603                    1001,
2604                    "prtry is shorter than the minimum length of 1".to_string(),
2605                ));
2606            }
2607            if val.chars().count() > 35 {
2608                return Err(ValidationError::new(
2609                    1002,
2610                    "prtry exceeds the maximum length of 35".to_string(),
2611                ));
2612            }
2613        }
2614        Ok(())
2615    }
2616}
2617
2618// Max15NumericText_fixed: 1
2619#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2620pub enum Max15NumericTextfixed {
2621    #[default]
2622    #[serde(rename = "1")]
2623    Code1,
2624}
2625
2626impl Max15NumericTextfixed {
2627    pub fn validate(&self) -> Result<(), ValidationError> {
2628        Ok(())
2629    }
2630}
2631
2632// NameAndAddress161: Postal address of a party.
2633#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2634pub struct NameAndAddress161 {
2635    #[serde(rename = "Nm")]
2636    pub nm: String,
2637    #[serde(rename = "Adr")]
2638    pub adr: PostalAddress242,
2639}
2640
2641impl NameAndAddress161 {
2642    pub fn validate(&self) -> Result<(), ValidationError> {
2643        if self.nm.chars().count() < 1 {
2644            return Err(ValidationError::new(
2645                1001,
2646                "nm is shorter than the minimum length of 1".to_string(),
2647            ));
2648        }
2649        if self.nm.chars().count() > 140 {
2650            return Err(ValidationError::new(
2651                1002,
2652                "nm exceeds the maximum length of 140".to_string(),
2653            ));
2654        }
2655        self.adr.validate()?;
2656        Ok(())
2657    }
2658}
2659
2660// NamePrefix2Code: Title of the person is gender neutral (Mx).
2661#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2662pub enum NamePrefix2Code {
2663    #[default]
2664    #[serde(rename = "DOCT")]
2665    CodeDOCT,
2666    #[serde(rename = "MADM")]
2667    CodeMADM,
2668    #[serde(rename = "MISS")]
2669    CodeMISS,
2670    #[serde(rename = "MIST")]
2671    CodeMIST,
2672    #[serde(rename = "MIKS")]
2673    CodeMIKS,
2674}
2675
2676impl NamePrefix2Code {
2677    pub fn validate(&self) -> Result<(), ValidationError> {
2678        Ok(())
2679    }
2680}
2681
2682// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
2683#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2684pub struct OrganisationIdentification291 {
2685    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
2686    pub any_bic: Option<String>,
2687    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
2688    pub lei: Option<String>,
2689    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
2690    pub othr: Option<Vec<GenericOrganisationIdentification1>>,
2691}
2692
2693impl OrganisationIdentification291 {
2694    pub fn validate(&self) -> Result<(), ValidationError> {
2695        if let Some(ref val) = self.any_bic {
2696            let pattern =
2697                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
2698            if !pattern.is_match(val) {
2699                return Err(ValidationError::new(
2700                    1005,
2701                    "any_bic does not match the required pattern".to_string(),
2702                ));
2703            }
2704        }
2705        if let Some(ref val) = self.lei {
2706            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
2707            if !pattern.is_match(val) {
2708                return Err(ValidationError::new(
2709                    1005,
2710                    "lei does not match the required pattern".to_string(),
2711                ));
2712            }
2713        }
2714        if let Some(ref vec) = self.othr {
2715            for item in vec {
2716                item.validate()?
2717            }
2718        }
2719        Ok(())
2720    }
2721}
2722
2723// OrganisationIdentification292: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
2724#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2725pub struct OrganisationIdentification292 {
2726    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
2727    pub any_bic: Option<String>,
2728    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
2729    pub lei: Option<String>,
2730    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
2731    pub othr: Option<Vec<GenericOrganisationIdentification11>>,
2732}
2733
2734impl OrganisationIdentification292 {
2735    pub fn validate(&self) -> Result<(), ValidationError> {
2736        if let Some(ref val) = self.any_bic {
2737            let pattern =
2738                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
2739            if !pattern.is_match(val) {
2740                return Err(ValidationError::new(
2741                    1005,
2742                    "any_bic does not match the required pattern".to_string(),
2743                ));
2744            }
2745        }
2746        if let Some(ref val) = self.lei {
2747            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
2748            if !pattern.is_match(val) {
2749                return Err(ValidationError::new(
2750                    1005,
2751                    "lei does not match the required pattern".to_string(),
2752                ));
2753            }
2754        }
2755        if let Some(ref vec) = self.othr {
2756            for item in vec {
2757                item.validate()?
2758            }
2759        }
2760        Ok(())
2761    }
2762}
2763
2764// OrganisationIdentificationSchemeName1Choice: Name of the identification scheme, in a free text form.
2765#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2766pub struct OrganisationIdentificationSchemeName1Choice {
2767    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2768    pub cd: Option<String>,
2769    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2770    pub prtry: Option<String>,
2771}
2772
2773impl OrganisationIdentificationSchemeName1Choice {
2774    pub fn validate(&self) -> Result<(), ValidationError> {
2775        if let Some(ref val) = self.cd {
2776            if val.chars().count() < 1 {
2777                return Err(ValidationError::new(
2778                    1001,
2779                    "cd is shorter than the minimum length of 1".to_string(),
2780                ));
2781            }
2782            if val.chars().count() > 4 {
2783                return Err(ValidationError::new(
2784                    1002,
2785                    "cd exceeds the maximum length of 4".to_string(),
2786                ));
2787            }
2788        }
2789        if let Some(ref val) = self.prtry {
2790            if val.chars().count() < 1 {
2791                return Err(ValidationError::new(
2792                    1001,
2793                    "prtry is shorter than the minimum length of 1".to_string(),
2794                ));
2795            }
2796            if val.chars().count() > 35 {
2797                return Err(ValidationError::new(
2798                    1002,
2799                    "prtry exceeds the maximum length of 35".to_string(),
2800                ));
2801            }
2802        }
2803        Ok(())
2804    }
2805}
2806
2807// OrganisationIdentificationSchemeName1Choice1: Name of the identification scheme, in a coded form as published in an external list.
2808#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2809pub struct OrganisationIdentificationSchemeName1Choice1 {
2810    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2811    pub cd: Option<String>,
2812}
2813
2814impl OrganisationIdentificationSchemeName1Choice1 {
2815    pub fn validate(&self) -> Result<(), ValidationError> {
2816        if let Some(ref val) = self.cd {
2817            if val.chars().count() < 1 {
2818                return Err(ValidationError::new(
2819                    1001,
2820                    "cd is shorter than the minimum length of 1".to_string(),
2821                ));
2822            }
2823            if val.chars().count() > 4 {
2824                return Err(ValidationError::new(
2825                    1002,
2826                    "cd exceeds the maximum length of 4".to_string(),
2827                ));
2828            }
2829        }
2830        Ok(())
2831    }
2832}
2833
2834// OtherContact1: Communication value such as phone number or email address.
2835#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2836pub struct OtherContact1 {
2837    #[serde(rename = "ChanlTp")]
2838    pub chanl_tp: String,
2839    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
2840    pub id: Option<String>,
2841}
2842
2843impl OtherContact1 {
2844    pub fn validate(&self) -> Result<(), ValidationError> {
2845        if self.chanl_tp.chars().count() < 1 {
2846            return Err(ValidationError::new(
2847                1001,
2848                "chanl_tp is shorter than the minimum length of 1".to_string(),
2849            ));
2850        }
2851        if self.chanl_tp.chars().count() > 4 {
2852            return Err(ValidationError::new(
2853                1002,
2854                "chanl_tp exceeds the maximum length of 4".to_string(),
2855            ));
2856        }
2857        if let Some(ref val) = self.id {
2858            if val.chars().count() < 1 {
2859                return Err(ValidationError::new(
2860                    1001,
2861                    "id is shorter than the minimum length of 1".to_string(),
2862                ));
2863            }
2864            if val.chars().count() > 128 {
2865                return Err(ValidationError::new(
2866                    1002,
2867                    "id exceeds the maximum length of 128".to_string(),
2868                ));
2869            }
2870        }
2871        Ok(())
2872    }
2873}
2874
2875// Party38Choice1: Unique and unambiguous identification of a person, for example a passport.
2876#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2877pub struct Party38Choice1 {
2878    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
2879    pub org_id: Option<OrganisationIdentification291>,
2880    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
2881    pub prvt_id: Option<PersonIdentification131>,
2882}
2883
2884impl Party38Choice1 {
2885    pub fn validate(&self) -> Result<(), ValidationError> {
2886        if let Some(ref val) = self.org_id {
2887            val.validate()?
2888        }
2889        if let Some(ref val) = self.prvt_id {
2890            val.validate()?
2891        }
2892        Ok(())
2893    }
2894}
2895
2896// Party38Choice2: Unique and unambiguous identification of a person, for example a passport.
2897#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2898pub struct Party38Choice2 {
2899    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
2900    pub org_id: Option<OrganisationIdentification292>,
2901    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
2902    pub prvt_id: Option<PersonIdentification132>,
2903}
2904
2905impl Party38Choice2 {
2906    pub fn validate(&self) -> Result<(), ValidationError> {
2907        if let Some(ref val) = self.org_id {
2908            val.validate()?
2909        }
2910        if let Some(ref val) = self.prvt_id {
2911            val.validate()?
2912        }
2913        Ok(())
2914    }
2915}
2916
2917// PartyIdentification1351: Set of elements used to indicate how to contact the party.
2918#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2919pub struct PartyIdentification1351 {
2920    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
2921    pub nm: Option<String>,
2922    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
2923    pub pstl_adr: Option<PostalAddress241>,
2924    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
2925    pub id: Option<Party38Choice1>,
2926    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
2927    pub ctry_of_res: Option<String>,
2928    #[serde(rename = "CtctDtls", skip_serializing_if = "Option::is_none")]
2929    pub ctct_dtls: Option<Contact4>,
2930}
2931
2932impl PartyIdentification1351 {
2933    pub fn validate(&self) -> Result<(), ValidationError> {
2934        if let Some(ref val) = self.nm {
2935            if val.chars().count() < 1 {
2936                return Err(ValidationError::new(
2937                    1001,
2938                    "nm is shorter than the minimum length of 1".to_string(),
2939                ));
2940            }
2941            if val.chars().count() > 140 {
2942                return Err(ValidationError::new(
2943                    1002,
2944                    "nm exceeds the maximum length of 140".to_string(),
2945                ));
2946            }
2947        }
2948        if let Some(ref val) = self.pstl_adr {
2949            val.validate()?
2950        }
2951        if let Some(ref val) = self.id {
2952            val.validate()?
2953        }
2954        if let Some(ref val) = self.ctry_of_res {
2955            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
2956            if !pattern.is_match(val) {
2957                return Err(ValidationError::new(
2958                    1005,
2959                    "ctry_of_res does not match the required pattern".to_string(),
2960                ));
2961            }
2962        }
2963        if let Some(ref val) = self.ctct_dtls {
2964            val.validate()?
2965        }
2966        Ok(())
2967    }
2968}
2969
2970// PartyIdentification1352: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
2971#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2972pub struct PartyIdentification1352 {
2973    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
2974    pub nm: Option<String>,
2975    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
2976    pub pstl_adr: Option<PostalAddress242>,
2977    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
2978    pub id: Option<Party38Choice2>,
2979    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
2980    pub ctry_of_res: Option<String>,
2981}
2982
2983impl PartyIdentification1352 {
2984    pub fn validate(&self) -> Result<(), ValidationError> {
2985        if let Some(ref val) = self.nm {
2986            if val.chars().count() < 1 {
2987                return Err(ValidationError::new(
2988                    1001,
2989                    "nm is shorter than the minimum length of 1".to_string(),
2990                ));
2991            }
2992            if val.chars().count() > 140 {
2993                return Err(ValidationError::new(
2994                    1002,
2995                    "nm exceeds the maximum length of 140".to_string(),
2996                ));
2997            }
2998        }
2999        if let Some(ref val) = self.pstl_adr {
3000            val.validate()?
3001        }
3002        if let Some(ref val) = self.id {
3003            val.validate()?
3004        }
3005        if let Some(ref val) = self.ctry_of_res {
3006            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3007            if !pattern.is_match(val) {
3008                return Err(ValidationError::new(
3009                    1005,
3010                    "ctry_of_res does not match the required pattern".to_string(),
3011                ));
3012            }
3013        }
3014        Ok(())
3015    }
3016}
3017
3018// PartyIdentification1353: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
3019#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3020pub struct PartyIdentification1353 {
3021    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
3022    pub nm: Option<String>,
3023    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
3024    pub pstl_adr: Option<PostalAddress241>,
3025    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
3026    pub id: Option<Party38Choice1>,
3027    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
3028    pub ctry_of_res: Option<String>,
3029}
3030
3031impl PartyIdentification1353 {
3032    pub fn validate(&self) -> Result<(), ValidationError> {
3033        if let Some(ref val) = self.nm {
3034            if val.chars().count() < 1 {
3035                return Err(ValidationError::new(
3036                    1001,
3037                    "nm is shorter than the minimum length of 1".to_string(),
3038                ));
3039            }
3040            if val.chars().count() > 140 {
3041                return Err(ValidationError::new(
3042                    1002,
3043                    "nm exceeds the maximum length of 140".to_string(),
3044                ));
3045            }
3046        }
3047        if let Some(ref val) = self.pstl_adr {
3048            val.validate()?
3049        }
3050        if let Some(ref val) = self.id {
3051            val.validate()?
3052        }
3053        if let Some(ref val) = self.ctry_of_res {
3054            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3055            if !pattern.is_match(val) {
3056                return Err(ValidationError::new(
3057                    1005,
3058                    "ctry_of_res does not match the required pattern".to_string(),
3059                ));
3060            }
3061        }
3062        Ok(())
3063    }
3064}
3065
3066// PartyIdentification1354: 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.
3067#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3068pub struct PartyIdentification1354 {
3069    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
3070    pub nm: Option<String>,
3071    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
3072    pub pstl_adr: Option<PostalAddress242>,
3073    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
3074    pub id: Option<Party38Choice1>,
3075    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
3076    pub ctry_of_res: Option<String>,
3077}
3078
3079impl PartyIdentification1354 {
3080    pub fn validate(&self) -> Result<(), ValidationError> {
3081        if let Some(ref val) = self.nm {
3082            if val.chars().count() < 1 {
3083                return Err(ValidationError::new(
3084                    1001,
3085                    "nm is shorter than the minimum length of 1".to_string(),
3086                ));
3087            }
3088            if val.chars().count() > 140 {
3089                return Err(ValidationError::new(
3090                    1002,
3091                    "nm exceeds the maximum length of 140".to_string(),
3092                ));
3093            }
3094        }
3095        if let Some(ref val) = self.pstl_adr {
3096            val.validate()?
3097        }
3098        if let Some(ref val) = self.id {
3099            val.validate()?
3100        }
3101        if let Some(ref val) = self.ctry_of_res {
3102            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3103            if !pattern.is_match(val) {
3104                return Err(ValidationError::new(
3105                    1005,
3106                    "ctry_of_res does not match the required pattern".to_string(),
3107                ));
3108            }
3109        }
3110        Ok(())
3111    }
3112}
3113
3114// PaymentIdentification61: Universally unique identifier to provide an end-to-end reference of a payment transaction.
3115#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3116pub struct PaymentIdentification61 {
3117    #[serde(rename = "InstrId", skip_serializing_if = "Option::is_none")]
3118    pub instr_id: Option<String>,
3119    #[serde(rename = "EndToEndId")]
3120    pub end_to_end_id: String,
3121    #[serde(rename = "UETR")]
3122    pub uetr: String,
3123}
3124
3125impl PaymentIdentification61 {
3126    pub fn validate(&self) -> Result<(), ValidationError> {
3127        if let Some(ref val) = self.instr_id {
3128            if val.chars().count() < 1 {
3129                return Err(ValidationError::new(
3130                    1001,
3131                    "instr_id is shorter than the minimum length of 1".to_string(),
3132                ));
3133            }
3134            if val.chars().count() > 35 {
3135                return Err(ValidationError::new(
3136                    1002,
3137                    "instr_id exceeds the maximum length of 35".to_string(),
3138                ));
3139            }
3140        }
3141        if self.end_to_end_id.chars().count() < 1 {
3142            return Err(ValidationError::new(
3143                1001,
3144                "end_to_end_id is shorter than the minimum length of 1".to_string(),
3145            ));
3146        }
3147        if self.end_to_end_id.chars().count() > 35 {
3148            return Err(ValidationError::new(
3149                1002,
3150                "end_to_end_id exceeds the maximum length of 35".to_string(),
3151            ));
3152        }
3153        let pattern =
3154            Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
3155                .unwrap();
3156        if !pattern.is_match(&self.uetr) {
3157            return Err(ValidationError::new(
3158                1005,
3159                "uetr does not match the required pattern".to_string(),
3160            ));
3161        }
3162        Ok(())
3163    }
3164}
3165
3166// PaymentInstruction301: Provides information on the individual transaction(s) included in the message.
3167#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3168pub struct PaymentInstruction301 {
3169    #[serde(rename = "PmtInfId")]
3170    pub pmt_inf_id: String,
3171    #[serde(rename = "PmtMtd")]
3172    pub pmt_mtd: PaymentMethod3Code1,
3173    #[serde(rename = "PmtTpInf", skip_serializing_if = "Option::is_none")]
3174    pub pmt_tp_inf: Option<PaymentTypeInformation261>,
3175    #[serde(rename = "ReqdExctnDt")]
3176    pub reqd_exctn_dt: DateAndDateTime2Choice,
3177    #[serde(rename = "PoolgAdjstmntDt", skip_serializing_if = "Option::is_none")]
3178    pub poolg_adjstmnt_dt: Option<String>,
3179    #[serde(rename = "Dbtr")]
3180    pub dbtr: PartyIdentification1352,
3181    #[serde(rename = "DbtrAcct")]
3182    pub dbtr_acct: CashAccount38,
3183    #[serde(rename = "DbtrAgt")]
3184    pub dbtr_agt: BranchAndFinancialInstitutionIdentification62,
3185    #[serde(rename = "DbtrAgtAcct", skip_serializing_if = "Option::is_none")]
3186    pub dbtr_agt_acct: Option<CashAccount38>,
3187    #[serde(rename = "InstrForDbtrAgt", skip_serializing_if = "Option::is_none")]
3188    pub instr_for_dbtr_agt: Option<String>,
3189    #[serde(rename = "UltmtDbtr", skip_serializing_if = "Option::is_none")]
3190    pub ultmt_dbtr: Option<PartyIdentification1353>,
3191    #[serde(rename = "ChrgBr", skip_serializing_if = "Option::is_none")]
3192    pub chrg_br: Option<ChargeBearerType1Code1>,
3193    #[serde(rename = "ChrgsAcct", skip_serializing_if = "Option::is_none")]
3194    pub chrgs_acct: Option<CashAccount38>,
3195    #[serde(rename = "ChrgsAcctAgt", skip_serializing_if = "Option::is_none")]
3196    pub chrgs_acct_agt: Option<BranchAndFinancialInstitutionIdentification6>,
3197    #[serde(rename = "CdtTrfTxInf")]
3198    pub cdt_trf_tx_inf: CreditTransferTransaction341,
3199}
3200
3201impl PaymentInstruction301 {
3202    pub fn validate(&self) -> Result<(), ValidationError> {
3203        if self.pmt_inf_id.chars().count() < 1 {
3204            return Err(ValidationError::new(
3205                1001,
3206                "pmt_inf_id is shorter than the minimum length of 1".to_string(),
3207            ));
3208        }
3209        if self.pmt_inf_id.chars().count() > 35 {
3210            return Err(ValidationError::new(
3211                1002,
3212                "pmt_inf_id exceeds the maximum length of 35".to_string(),
3213            ));
3214        }
3215        self.pmt_mtd.validate()?;
3216        if let Some(ref val) = self.pmt_tp_inf {
3217            val.validate()?
3218        }
3219        self.reqd_exctn_dt.validate()?;
3220        self.dbtr.validate()?;
3221        self.dbtr_acct.validate()?;
3222        self.dbtr_agt.validate()?;
3223        if let Some(ref val) = self.dbtr_agt_acct {
3224            val.validate()?
3225        }
3226        if let Some(ref val) = self.instr_for_dbtr_agt {
3227            if val.chars().count() < 1 {
3228                return Err(ValidationError::new(
3229                    1001,
3230                    "instr_for_dbtr_agt is shorter than the minimum length of 1".to_string(),
3231                ));
3232            }
3233            if val.chars().count() > 140 {
3234                return Err(ValidationError::new(
3235                    1002,
3236                    "instr_for_dbtr_agt exceeds the maximum length of 140".to_string(),
3237                ));
3238            }
3239        }
3240        if let Some(ref val) = self.ultmt_dbtr {
3241            val.validate()?
3242        }
3243        if let Some(ref val) = self.chrg_br {
3244            val.validate()?
3245        }
3246        if let Some(ref val) = self.chrgs_acct {
3247            val.validate()?
3248        }
3249        if let Some(ref val) = self.chrgs_acct_agt {
3250            val.validate()?
3251        }
3252        self.cdt_trf_tx_inf.validate()?;
3253        Ok(())
3254    }
3255}
3256
3257// PaymentMethod3Code__1: Transfer of an amount of money in the books of the account servicer.
3258#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3259pub enum PaymentMethod3Code1 {
3260    #[default]
3261    #[serde(rename = "CHK")]
3262    CodeCHK,
3263    #[serde(rename = "TRF")]
3264    CodeTRF,
3265}
3266
3267impl PaymentMethod3Code1 {
3268    pub fn validate(&self) -> Result<(), ValidationError> {
3269        Ok(())
3270    }
3271}
3272
3273// PaymentTypeInformation261: Specifies the high level purpose of the instruction based on a set of pre-defined categories.
3274// Usage: This is used by the initiating party to provide information concerning the processing of the payment. It is likely to trigger special processing by any of the agents involved in the payment chain.
3275#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3276pub struct PaymentTypeInformation261 {
3277    #[serde(rename = "InstrPrty", skip_serializing_if = "Option::is_none")]
3278    pub instr_prty: Option<Priority2Code>,
3279    #[serde(rename = "SvcLvl", skip_serializing_if = "Option::is_none")]
3280    pub svc_lvl: Option<Vec<ServiceLevel8Choice>>,
3281    #[serde(rename = "LclInstrm", skip_serializing_if = "Option::is_none")]
3282    pub lcl_instrm: Option<LocalInstrument2Choice>,
3283    #[serde(rename = "CtgyPurp", skip_serializing_if = "Option::is_none")]
3284    pub ctgy_purp: Option<CategoryPurpose1Choice>,
3285}
3286
3287impl PaymentTypeInformation261 {
3288    pub fn validate(&self) -> Result<(), ValidationError> {
3289        if let Some(ref val) = self.instr_prty {
3290            val.validate()?
3291        }
3292        if let Some(ref vec) = self.svc_lvl {
3293            for item in vec {
3294                item.validate()?
3295            }
3296        }
3297        if let Some(ref val) = self.lcl_instrm {
3298            val.validate()?
3299        }
3300        if let Some(ref val) = self.ctgy_purp {
3301            val.validate()?
3302        }
3303        Ok(())
3304    }
3305}
3306
3307// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
3308#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3309pub struct PersonIdentification131 {
3310    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
3311    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth1>,
3312    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
3313    pub othr: Option<Vec<GenericPersonIdentification1>>,
3314}
3315
3316impl PersonIdentification131 {
3317    pub fn validate(&self) -> Result<(), ValidationError> {
3318        if let Some(ref val) = self.dt_and_plc_of_birth {
3319            val.validate()?
3320        }
3321        if let Some(ref vec) = self.othr {
3322            for item in vec {
3323                item.validate()?
3324            }
3325        }
3326        Ok(())
3327    }
3328}
3329
3330// PersonIdentification132: Unique identification of a person, as assigned by an institution, using an identification scheme.
3331#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3332pub struct PersonIdentification132 {
3333    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
3334    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth1>,
3335    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
3336    pub othr: Option<Vec<GenericPersonIdentification11>>,
3337}
3338
3339impl PersonIdentification132 {
3340    pub fn validate(&self) -> Result<(), ValidationError> {
3341        if let Some(ref val) = self.dt_and_plc_of_birth {
3342            val.validate()?
3343        }
3344        if let Some(ref vec) = self.othr {
3345            for item in vec {
3346                item.validate()?
3347            }
3348        }
3349        Ok(())
3350    }
3351}
3352
3353// PersonIdentificationSchemeName1Choice: Name of the identification scheme, in a free text form.
3354#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3355pub struct PersonIdentificationSchemeName1Choice {
3356    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
3357    pub cd: Option<String>,
3358    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
3359    pub prtry: Option<String>,
3360}
3361
3362impl PersonIdentificationSchemeName1Choice {
3363    pub fn validate(&self) -> Result<(), ValidationError> {
3364        if let Some(ref val) = self.cd {
3365            if val.chars().count() < 1 {
3366                return Err(ValidationError::new(
3367                    1001,
3368                    "cd is shorter than the minimum length of 1".to_string(),
3369                ));
3370            }
3371            if val.chars().count() > 4 {
3372                return Err(ValidationError::new(
3373                    1002,
3374                    "cd exceeds the maximum length of 4".to_string(),
3375                ));
3376            }
3377        }
3378        if let Some(ref val) = self.prtry {
3379            if val.chars().count() < 1 {
3380                return Err(ValidationError::new(
3381                    1001,
3382                    "prtry is shorter than the minimum length of 1".to_string(),
3383                ));
3384            }
3385            if val.chars().count() > 35 {
3386                return Err(ValidationError::new(
3387                    1002,
3388                    "prtry exceeds the maximum length of 35".to_string(),
3389                ));
3390            }
3391        }
3392        Ok(())
3393    }
3394}
3395
3396// PersonIdentificationSchemeName1Choice1: Name of the identification scheme, in a coded form as published in an external list.
3397#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3398pub struct PersonIdentificationSchemeName1Choice1 {
3399    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
3400    pub cd: Option<String>,
3401}
3402
3403impl PersonIdentificationSchemeName1Choice1 {
3404    pub fn validate(&self) -> Result<(), ValidationError> {
3405        if let Some(ref val) = self.cd {
3406            if val.chars().count() < 1 {
3407                return Err(ValidationError::new(
3408                    1001,
3409                    "cd is shorter than the minimum length of 1".to_string(),
3410                ));
3411            }
3412            if val.chars().count() > 4 {
3413                return Err(ValidationError::new(
3414                    1002,
3415                    "cd exceeds the maximum length of 4".to_string(),
3416                ));
3417            }
3418        }
3419        Ok(())
3420    }
3421}
3422
3423// PostalAddress24: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
3424#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3425pub struct PostalAddress24 {
3426    #[serde(rename = "AdrTp", skip_serializing_if = "Option::is_none")]
3427    pub adr_tp: Option<AddressType3Choice>,
3428    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
3429    pub dept: Option<String>,
3430    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
3431    pub sub_dept: Option<String>,
3432    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
3433    pub strt_nm: Option<String>,
3434    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
3435    pub bldg_nb: Option<String>,
3436    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
3437    pub bldg_nm: Option<String>,
3438    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
3439    pub flr: Option<String>,
3440    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
3441    pub pst_bx: Option<String>,
3442    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
3443    pub room: Option<String>,
3444    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
3445    pub pst_cd: Option<String>,
3446    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
3447    pub twn_nm: Option<String>,
3448    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
3449    pub twn_lctn_nm: Option<String>,
3450    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
3451    pub dstrct_nm: Option<String>,
3452    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
3453    pub ctry_sub_dvsn: Option<String>,
3454    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
3455    pub ctry: Option<String>,
3456    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
3457    pub adr_line: Option<Vec<String>>,
3458}
3459
3460impl PostalAddress24 {
3461    pub fn validate(&self) -> Result<(), ValidationError> {
3462        if let Some(ref val) = self.adr_tp {
3463            val.validate()?
3464        }
3465        if let Some(ref val) = self.dept {
3466            if val.chars().count() < 1 {
3467                return Err(ValidationError::new(
3468                    1001,
3469                    "dept is shorter than the minimum length of 1".to_string(),
3470                ));
3471            }
3472            if val.chars().count() > 70 {
3473                return Err(ValidationError::new(
3474                    1002,
3475                    "dept exceeds the maximum length of 70".to_string(),
3476                ));
3477            }
3478        }
3479        if let Some(ref val) = self.sub_dept {
3480            if val.chars().count() < 1 {
3481                return Err(ValidationError::new(
3482                    1001,
3483                    "sub_dept is shorter than the minimum length of 1".to_string(),
3484                ));
3485            }
3486            if val.chars().count() > 70 {
3487                return Err(ValidationError::new(
3488                    1002,
3489                    "sub_dept exceeds the maximum length of 70".to_string(),
3490                ));
3491            }
3492        }
3493        if let Some(ref val) = self.strt_nm {
3494            if val.chars().count() < 1 {
3495                return Err(ValidationError::new(
3496                    1001,
3497                    "strt_nm is shorter than the minimum length of 1".to_string(),
3498                ));
3499            }
3500            if val.chars().count() > 70 {
3501                return Err(ValidationError::new(
3502                    1002,
3503                    "strt_nm exceeds the maximum length of 70".to_string(),
3504                ));
3505            }
3506        }
3507        if let Some(ref val) = self.bldg_nb {
3508            if val.chars().count() < 1 {
3509                return Err(ValidationError::new(
3510                    1001,
3511                    "bldg_nb is shorter than the minimum length of 1".to_string(),
3512                ));
3513            }
3514            if val.chars().count() > 16 {
3515                return Err(ValidationError::new(
3516                    1002,
3517                    "bldg_nb exceeds the maximum length of 16".to_string(),
3518                ));
3519            }
3520        }
3521        if let Some(ref val) = self.bldg_nm {
3522            if val.chars().count() < 1 {
3523                return Err(ValidationError::new(
3524                    1001,
3525                    "bldg_nm is shorter than the minimum length of 1".to_string(),
3526                ));
3527            }
3528            if val.chars().count() > 35 {
3529                return Err(ValidationError::new(
3530                    1002,
3531                    "bldg_nm exceeds the maximum length of 35".to_string(),
3532                ));
3533            }
3534        }
3535        if let Some(ref val) = self.flr {
3536            if val.chars().count() < 1 {
3537                return Err(ValidationError::new(
3538                    1001,
3539                    "flr is shorter than the minimum length of 1".to_string(),
3540                ));
3541            }
3542            if val.chars().count() > 70 {
3543                return Err(ValidationError::new(
3544                    1002,
3545                    "flr exceeds the maximum length of 70".to_string(),
3546                ));
3547            }
3548        }
3549        if let Some(ref val) = self.pst_bx {
3550            if val.chars().count() < 1 {
3551                return Err(ValidationError::new(
3552                    1001,
3553                    "pst_bx is shorter than the minimum length of 1".to_string(),
3554                ));
3555            }
3556            if val.chars().count() > 16 {
3557                return Err(ValidationError::new(
3558                    1002,
3559                    "pst_bx exceeds the maximum length of 16".to_string(),
3560                ));
3561            }
3562        }
3563        if let Some(ref val) = self.room {
3564            if val.chars().count() < 1 {
3565                return Err(ValidationError::new(
3566                    1001,
3567                    "room is shorter than the minimum length of 1".to_string(),
3568                ));
3569            }
3570            if val.chars().count() > 70 {
3571                return Err(ValidationError::new(
3572                    1002,
3573                    "room exceeds the maximum length of 70".to_string(),
3574                ));
3575            }
3576        }
3577        if let Some(ref val) = self.pst_cd {
3578            if val.chars().count() < 1 {
3579                return Err(ValidationError::new(
3580                    1001,
3581                    "pst_cd is shorter than the minimum length of 1".to_string(),
3582                ));
3583            }
3584            if val.chars().count() > 16 {
3585                return Err(ValidationError::new(
3586                    1002,
3587                    "pst_cd exceeds the maximum length of 16".to_string(),
3588                ));
3589            }
3590        }
3591        if let Some(ref val) = self.twn_nm {
3592            if val.chars().count() < 1 {
3593                return Err(ValidationError::new(
3594                    1001,
3595                    "twn_nm is shorter than the minimum length of 1".to_string(),
3596                ));
3597            }
3598            if val.chars().count() > 35 {
3599                return Err(ValidationError::new(
3600                    1002,
3601                    "twn_nm exceeds the maximum length of 35".to_string(),
3602                ));
3603            }
3604        }
3605        if let Some(ref val) = self.twn_lctn_nm {
3606            if val.chars().count() < 1 {
3607                return Err(ValidationError::new(
3608                    1001,
3609                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
3610                ));
3611            }
3612            if val.chars().count() > 35 {
3613                return Err(ValidationError::new(
3614                    1002,
3615                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
3616                ));
3617            }
3618        }
3619        if let Some(ref val) = self.dstrct_nm {
3620            if val.chars().count() < 1 {
3621                return Err(ValidationError::new(
3622                    1001,
3623                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
3624                ));
3625            }
3626            if val.chars().count() > 35 {
3627                return Err(ValidationError::new(
3628                    1002,
3629                    "dstrct_nm exceeds the maximum length of 35".to_string(),
3630                ));
3631            }
3632        }
3633        if let Some(ref val) = self.ctry_sub_dvsn {
3634            if val.chars().count() < 1 {
3635                return Err(ValidationError::new(
3636                    1001,
3637                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
3638                ));
3639            }
3640            if val.chars().count() > 35 {
3641                return Err(ValidationError::new(
3642                    1002,
3643                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
3644                ));
3645            }
3646        }
3647        if let Some(ref val) = self.ctry {
3648            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3649            if !pattern.is_match(val) {
3650                return Err(ValidationError::new(
3651                    1005,
3652                    "ctry does not match the required pattern".to_string(),
3653                ));
3654            }
3655        }
3656        if let Some(ref vec) = self.adr_line {
3657            for item in vec {
3658                if item.chars().count() < 1 {
3659                    return Err(ValidationError::new(
3660                        1001,
3661                        "adr_line is shorter than the minimum length of 1".to_string(),
3662                    ));
3663                }
3664                if item.chars().count() > 70 {
3665                    return Err(ValidationError::new(
3666                        1002,
3667                        "adr_line exceeds the maximum length of 70".to_string(),
3668                    ));
3669                }
3670            }
3671        }
3672        Ok(())
3673    }
3674}
3675
3676// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
3677#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3678pub struct PostalAddress241 {
3679    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
3680    pub dept: Option<String>,
3681    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
3682    pub sub_dept: Option<String>,
3683    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
3684    pub strt_nm: Option<String>,
3685    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
3686    pub bldg_nb: Option<String>,
3687    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
3688    pub bldg_nm: Option<String>,
3689    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
3690    pub flr: Option<String>,
3691    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
3692    pub pst_bx: Option<String>,
3693    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
3694    pub room: Option<String>,
3695    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
3696    pub pst_cd: Option<String>,
3697    #[serde(rename = "TwnNm")]
3698    pub twn_nm: String,
3699    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
3700    pub twn_lctn_nm: Option<String>,
3701    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
3702    pub dstrct_nm: Option<String>,
3703    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
3704    pub ctry_sub_dvsn: Option<String>,
3705    #[serde(rename = "Ctry")]
3706    pub ctry: String,
3707    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
3708    pub adr_line: Option<Vec<String>>,
3709}
3710
3711impl PostalAddress241 {
3712    pub fn validate(&self) -> Result<(), ValidationError> {
3713        if let Some(ref val) = self.dept {
3714            if val.chars().count() < 1 {
3715                return Err(ValidationError::new(
3716                    1001,
3717                    "dept is shorter than the minimum length of 1".to_string(),
3718                ));
3719            }
3720            if val.chars().count() > 70 {
3721                return Err(ValidationError::new(
3722                    1002,
3723                    "dept exceeds the maximum length of 70".to_string(),
3724                ));
3725            }
3726        }
3727        if let Some(ref val) = self.sub_dept {
3728            if val.chars().count() < 1 {
3729                return Err(ValidationError::new(
3730                    1001,
3731                    "sub_dept is shorter than the minimum length of 1".to_string(),
3732                ));
3733            }
3734            if val.chars().count() > 70 {
3735                return Err(ValidationError::new(
3736                    1002,
3737                    "sub_dept exceeds the maximum length of 70".to_string(),
3738                ));
3739            }
3740        }
3741        if let Some(ref val) = self.strt_nm {
3742            if val.chars().count() < 1 {
3743                return Err(ValidationError::new(
3744                    1001,
3745                    "strt_nm is shorter than the minimum length of 1".to_string(),
3746                ));
3747            }
3748            if val.chars().count() > 70 {
3749                return Err(ValidationError::new(
3750                    1002,
3751                    "strt_nm exceeds the maximum length of 70".to_string(),
3752                ));
3753            }
3754        }
3755        if let Some(ref val) = self.bldg_nb {
3756            if val.chars().count() < 1 {
3757                return Err(ValidationError::new(
3758                    1001,
3759                    "bldg_nb is shorter than the minimum length of 1".to_string(),
3760                ));
3761            }
3762            if val.chars().count() > 16 {
3763                return Err(ValidationError::new(
3764                    1002,
3765                    "bldg_nb exceeds the maximum length of 16".to_string(),
3766                ));
3767            }
3768        }
3769        if let Some(ref val) = self.bldg_nm {
3770            if val.chars().count() < 1 {
3771                return Err(ValidationError::new(
3772                    1001,
3773                    "bldg_nm is shorter than the minimum length of 1".to_string(),
3774                ));
3775            }
3776            if val.chars().count() > 35 {
3777                return Err(ValidationError::new(
3778                    1002,
3779                    "bldg_nm exceeds the maximum length of 35".to_string(),
3780                ));
3781            }
3782        }
3783        if let Some(ref val) = self.flr {
3784            if val.chars().count() < 1 {
3785                return Err(ValidationError::new(
3786                    1001,
3787                    "flr is shorter than the minimum length of 1".to_string(),
3788                ));
3789            }
3790            if val.chars().count() > 70 {
3791                return Err(ValidationError::new(
3792                    1002,
3793                    "flr exceeds the maximum length of 70".to_string(),
3794                ));
3795            }
3796        }
3797        if let Some(ref val) = self.pst_bx {
3798            if val.chars().count() < 1 {
3799                return Err(ValidationError::new(
3800                    1001,
3801                    "pst_bx is shorter than the minimum length of 1".to_string(),
3802                ));
3803            }
3804            if val.chars().count() > 16 {
3805                return Err(ValidationError::new(
3806                    1002,
3807                    "pst_bx exceeds the maximum length of 16".to_string(),
3808                ));
3809            }
3810        }
3811        if let Some(ref val) = self.room {
3812            if val.chars().count() < 1 {
3813                return Err(ValidationError::new(
3814                    1001,
3815                    "room is shorter than the minimum length of 1".to_string(),
3816                ));
3817            }
3818            if val.chars().count() > 70 {
3819                return Err(ValidationError::new(
3820                    1002,
3821                    "room exceeds the maximum length of 70".to_string(),
3822                ));
3823            }
3824        }
3825        if let Some(ref val) = self.pst_cd {
3826            if val.chars().count() < 1 {
3827                return Err(ValidationError::new(
3828                    1001,
3829                    "pst_cd is shorter than the minimum length of 1".to_string(),
3830                ));
3831            }
3832            if val.chars().count() > 16 {
3833                return Err(ValidationError::new(
3834                    1002,
3835                    "pst_cd exceeds the maximum length of 16".to_string(),
3836                ));
3837            }
3838        }
3839        if self.twn_nm.chars().count() < 1 {
3840            return Err(ValidationError::new(
3841                1001,
3842                "twn_nm is shorter than the minimum length of 1".to_string(),
3843            ));
3844        }
3845        if self.twn_nm.chars().count() > 35 {
3846            return Err(ValidationError::new(
3847                1002,
3848                "twn_nm exceeds the maximum length of 35".to_string(),
3849            ));
3850        }
3851        if let Some(ref val) = self.twn_lctn_nm {
3852            if val.chars().count() < 1 {
3853                return Err(ValidationError::new(
3854                    1001,
3855                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
3856                ));
3857            }
3858            if val.chars().count() > 35 {
3859                return Err(ValidationError::new(
3860                    1002,
3861                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
3862                ));
3863            }
3864        }
3865        if let Some(ref val) = self.dstrct_nm {
3866            if val.chars().count() < 1 {
3867                return Err(ValidationError::new(
3868                    1001,
3869                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
3870                ));
3871            }
3872            if val.chars().count() > 35 {
3873                return Err(ValidationError::new(
3874                    1002,
3875                    "dstrct_nm exceeds the maximum length of 35".to_string(),
3876                ));
3877            }
3878        }
3879        if let Some(ref val) = self.ctry_sub_dvsn {
3880            if val.chars().count() < 1 {
3881                return Err(ValidationError::new(
3882                    1001,
3883                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
3884                ));
3885            }
3886            if val.chars().count() > 35 {
3887                return Err(ValidationError::new(
3888                    1002,
3889                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
3890                ));
3891            }
3892        }
3893        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3894        if !pattern.is_match(&self.ctry) {
3895            return Err(ValidationError::new(
3896                1005,
3897                "ctry does not match the required pattern".to_string(),
3898            ));
3899        }
3900        if let Some(ref vec) = self.adr_line {
3901            for item in vec {
3902                if item.chars().count() < 1 {
3903                    return Err(ValidationError::new(
3904                        1001,
3905                        "adr_line is shorter than the minimum length of 1".to_string(),
3906                    ));
3907                }
3908                if item.chars().count() > 70 {
3909                    return Err(ValidationError::new(
3910                        1002,
3911                        "adr_line exceeds the maximum length of 70".to_string(),
3912                    ));
3913                }
3914            }
3915        }
3916        Ok(())
3917    }
3918}
3919
3920// PostalAddress242: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
3921#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3922pub struct PostalAddress242 {
3923    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
3924    pub dept: Option<String>,
3925    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
3926    pub sub_dept: Option<String>,
3927    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
3928    pub strt_nm: Option<String>,
3929    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
3930    pub bldg_nb: Option<String>,
3931    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
3932    pub bldg_nm: Option<String>,
3933    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
3934    pub flr: Option<String>,
3935    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
3936    pub pst_bx: Option<String>,
3937    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
3938    pub room: Option<String>,
3939    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
3940    pub pst_cd: Option<String>,
3941    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
3942    pub twn_nm: Option<String>,
3943    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
3944    pub twn_lctn_nm: Option<String>,
3945    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
3946    pub dstrct_nm: Option<String>,
3947    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
3948    pub ctry_sub_dvsn: Option<String>,
3949    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
3950    pub ctry: Option<String>,
3951    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
3952    pub adr_line: Option<Vec<String>>,
3953}
3954
3955impl PostalAddress242 {
3956    pub fn validate(&self) -> Result<(), ValidationError> {
3957        if let Some(ref val) = self.dept {
3958            if val.chars().count() < 1 {
3959                return Err(ValidationError::new(
3960                    1001,
3961                    "dept is shorter than the minimum length of 1".to_string(),
3962                ));
3963            }
3964            if val.chars().count() > 70 {
3965                return Err(ValidationError::new(
3966                    1002,
3967                    "dept exceeds the maximum length of 70".to_string(),
3968                ));
3969            }
3970        }
3971        if let Some(ref val) = self.sub_dept {
3972            if val.chars().count() < 1 {
3973                return Err(ValidationError::new(
3974                    1001,
3975                    "sub_dept is shorter than the minimum length of 1".to_string(),
3976                ));
3977            }
3978            if val.chars().count() > 70 {
3979                return Err(ValidationError::new(
3980                    1002,
3981                    "sub_dept exceeds the maximum length of 70".to_string(),
3982                ));
3983            }
3984        }
3985        if let Some(ref val) = self.strt_nm {
3986            if val.chars().count() < 1 {
3987                return Err(ValidationError::new(
3988                    1001,
3989                    "strt_nm is shorter than the minimum length of 1".to_string(),
3990                ));
3991            }
3992            if val.chars().count() > 70 {
3993                return Err(ValidationError::new(
3994                    1002,
3995                    "strt_nm exceeds the maximum length of 70".to_string(),
3996                ));
3997            }
3998        }
3999        if let Some(ref val) = self.bldg_nb {
4000            if val.chars().count() < 1 {
4001                return Err(ValidationError::new(
4002                    1001,
4003                    "bldg_nb is shorter than the minimum length of 1".to_string(),
4004                ));
4005            }
4006            if val.chars().count() > 16 {
4007                return Err(ValidationError::new(
4008                    1002,
4009                    "bldg_nb exceeds the maximum length of 16".to_string(),
4010                ));
4011            }
4012        }
4013        if let Some(ref val) = self.bldg_nm {
4014            if val.chars().count() < 1 {
4015                return Err(ValidationError::new(
4016                    1001,
4017                    "bldg_nm is shorter than the minimum length of 1".to_string(),
4018                ));
4019            }
4020            if val.chars().count() > 35 {
4021                return Err(ValidationError::new(
4022                    1002,
4023                    "bldg_nm exceeds the maximum length of 35".to_string(),
4024                ));
4025            }
4026        }
4027        if let Some(ref val) = self.flr {
4028            if val.chars().count() < 1 {
4029                return Err(ValidationError::new(
4030                    1001,
4031                    "flr is shorter than the minimum length of 1".to_string(),
4032                ));
4033            }
4034            if val.chars().count() > 70 {
4035                return Err(ValidationError::new(
4036                    1002,
4037                    "flr exceeds the maximum length of 70".to_string(),
4038                ));
4039            }
4040        }
4041        if let Some(ref val) = self.pst_bx {
4042            if val.chars().count() < 1 {
4043                return Err(ValidationError::new(
4044                    1001,
4045                    "pst_bx is shorter than the minimum length of 1".to_string(),
4046                ));
4047            }
4048            if val.chars().count() > 16 {
4049                return Err(ValidationError::new(
4050                    1002,
4051                    "pst_bx exceeds the maximum length of 16".to_string(),
4052                ));
4053            }
4054        }
4055        if let Some(ref val) = self.room {
4056            if val.chars().count() < 1 {
4057                return Err(ValidationError::new(
4058                    1001,
4059                    "room is shorter than the minimum length of 1".to_string(),
4060                ));
4061            }
4062            if val.chars().count() > 70 {
4063                return Err(ValidationError::new(
4064                    1002,
4065                    "room exceeds the maximum length of 70".to_string(),
4066                ));
4067            }
4068        }
4069        if let Some(ref val) = self.pst_cd {
4070            if val.chars().count() < 1 {
4071                return Err(ValidationError::new(
4072                    1001,
4073                    "pst_cd is shorter than the minimum length of 1".to_string(),
4074                ));
4075            }
4076            if val.chars().count() > 16 {
4077                return Err(ValidationError::new(
4078                    1002,
4079                    "pst_cd exceeds the maximum length of 16".to_string(),
4080                ));
4081            }
4082        }
4083        if let Some(ref val) = self.twn_nm {
4084            if val.chars().count() < 1 {
4085                return Err(ValidationError::new(
4086                    1001,
4087                    "twn_nm is shorter than the minimum length of 1".to_string(),
4088                ));
4089            }
4090            if val.chars().count() > 35 {
4091                return Err(ValidationError::new(
4092                    1002,
4093                    "twn_nm exceeds the maximum length of 35".to_string(),
4094                ));
4095            }
4096        }
4097        if let Some(ref val) = self.twn_lctn_nm {
4098            if val.chars().count() < 1 {
4099                return Err(ValidationError::new(
4100                    1001,
4101                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
4102                ));
4103            }
4104            if val.chars().count() > 35 {
4105                return Err(ValidationError::new(
4106                    1002,
4107                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
4108                ));
4109            }
4110        }
4111        if let Some(ref val) = self.dstrct_nm {
4112            if val.chars().count() < 1 {
4113                return Err(ValidationError::new(
4114                    1001,
4115                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
4116                ));
4117            }
4118            if val.chars().count() > 35 {
4119                return Err(ValidationError::new(
4120                    1002,
4121                    "dstrct_nm exceeds the maximum length of 35".to_string(),
4122                ));
4123            }
4124        }
4125        if let Some(ref val) = self.ctry_sub_dvsn {
4126            if val.chars().count() < 1 {
4127                return Err(ValidationError::new(
4128                    1001,
4129                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
4130                ));
4131            }
4132            if val.chars().count() > 35 {
4133                return Err(ValidationError::new(
4134                    1002,
4135                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
4136                ));
4137            }
4138        }
4139        if let Some(ref val) = self.ctry {
4140            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
4141            if !pattern.is_match(val) {
4142                return Err(ValidationError::new(
4143                    1005,
4144                    "ctry does not match the required pattern".to_string(),
4145                ));
4146            }
4147        }
4148        if let Some(ref vec) = self.adr_line {
4149            for item in vec {
4150                if item.chars().count() < 1 {
4151                    return Err(ValidationError::new(
4152                        1001,
4153                        "adr_line is shorter than the minimum length of 1".to_string(),
4154                    ));
4155                }
4156                if item.chars().count() > 70 {
4157                    return Err(ValidationError::new(
4158                        1002,
4159                        "adr_line exceeds the maximum length of 70".to_string(),
4160                    ));
4161                }
4162            }
4163        }
4164        Ok(())
4165    }
4166}
4167
4168// PreferredContactMethod1Code: Preferred method used to reach the contact is per mobile or cell phone.
4169#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4170pub enum PreferredContactMethod1Code {
4171    #[default]
4172    #[serde(rename = "LETT")]
4173    CodeLETT,
4174    #[serde(rename = "MAIL")]
4175    CodeMAIL,
4176    #[serde(rename = "PHON")]
4177    CodePHON,
4178    #[serde(rename = "FAXX")]
4179    CodeFAXX,
4180    #[serde(rename = "CELL")]
4181    CodeCELL,
4182}
4183
4184impl PreferredContactMethod1Code {
4185    pub fn validate(&self) -> Result<(), ValidationError> {
4186        Ok(())
4187    }
4188}
4189
4190// Priority2Code: Priority level is normal.
4191#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4192pub enum Priority2Code {
4193    #[default]
4194    #[serde(rename = "HIGH")]
4195    CodeHIGH,
4196    #[serde(rename = "NORM")]
4197    CodeNORM,
4198}
4199
4200impl Priority2Code {
4201    pub fn validate(&self) -> Result<(), ValidationError> {
4202        Ok(())
4203    }
4204}
4205
4206// ProxyAccountIdentification1: Identification used to indicate the account identification under another specified name.
4207#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4208pub struct ProxyAccountIdentification1 {
4209    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
4210    pub tp: Option<ProxyAccountType1Choice>,
4211    #[serde(rename = "Id")]
4212    pub id: String,
4213}
4214
4215impl ProxyAccountIdentification1 {
4216    pub fn validate(&self) -> Result<(), ValidationError> {
4217        if let Some(ref val) = self.tp {
4218            val.validate()?
4219        }
4220        if self.id.chars().count() < 1 {
4221            return Err(ValidationError::new(
4222                1001,
4223                "id is shorter than the minimum length of 1".to_string(),
4224            ));
4225        }
4226        if self.id.chars().count() > 2048 {
4227            return Err(ValidationError::new(
4228                1002,
4229                "id exceeds the maximum length of 2048".to_string(),
4230            ));
4231        }
4232        Ok(())
4233    }
4234}
4235
4236// ProxyAccountType1Choice: Name of the identification scheme, in a free text form.
4237#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4238pub struct ProxyAccountType1Choice {
4239    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4240    pub cd: Option<String>,
4241    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
4242    pub prtry: Option<String>,
4243}
4244
4245impl ProxyAccountType1Choice {
4246    pub fn validate(&self) -> Result<(), ValidationError> {
4247        if let Some(ref val) = self.cd {
4248            if val.chars().count() < 1 {
4249                return Err(ValidationError::new(
4250                    1001,
4251                    "cd is shorter than the minimum length of 1".to_string(),
4252                ));
4253            }
4254            if val.chars().count() > 4 {
4255                return Err(ValidationError::new(
4256                    1002,
4257                    "cd exceeds the maximum length of 4".to_string(),
4258                ));
4259            }
4260        }
4261        if let Some(ref val) = self.prtry {
4262            if val.chars().count() < 1 {
4263                return Err(ValidationError::new(
4264                    1001,
4265                    "prtry is shorter than the minimum length of 1".to_string(),
4266                ));
4267            }
4268            if val.chars().count() > 35 {
4269                return Err(ValidationError::new(
4270                    1002,
4271                    "prtry exceeds the maximum length of 35".to_string(),
4272                ));
4273            }
4274        }
4275        Ok(())
4276    }
4277}
4278
4279// Purpose2Choice: Purpose, in a proprietary form.
4280#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4281pub struct Purpose2Choice {
4282    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4283    pub cd: Option<String>,
4284    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
4285    pub prtry: Option<String>,
4286}
4287
4288impl Purpose2Choice {
4289    pub fn validate(&self) -> Result<(), ValidationError> {
4290        if let Some(ref val) = self.cd {
4291            if val.chars().count() < 1 {
4292                return Err(ValidationError::new(
4293                    1001,
4294                    "cd is shorter than the minimum length of 1".to_string(),
4295                ));
4296            }
4297            if val.chars().count() > 4 {
4298                return Err(ValidationError::new(
4299                    1002,
4300                    "cd exceeds the maximum length of 4".to_string(),
4301                ));
4302            }
4303        }
4304        if let Some(ref val) = self.prtry {
4305            if val.chars().count() < 1 {
4306                return Err(ValidationError::new(
4307                    1001,
4308                    "prtry is shorter than the minimum length of 1".to_string(),
4309                ));
4310            }
4311            if val.chars().count() > 35 {
4312                return Err(ValidationError::new(
4313                    1002,
4314                    "prtry exceeds the maximum length of 35".to_string(),
4315                ));
4316            }
4317        }
4318        Ok(())
4319    }
4320}
4321
4322// ReferredDocumentInformation7: Set of elements used to provide the content of the referred document line.
4323#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4324pub struct ReferredDocumentInformation7 {
4325    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
4326    pub tp: Option<ReferredDocumentType4>,
4327    #[serde(rename = "Nb", skip_serializing_if = "Option::is_none")]
4328    pub nb: Option<String>,
4329    #[serde(rename = "RltdDt", skip_serializing_if = "Option::is_none")]
4330    pub rltd_dt: Option<String>,
4331    #[serde(rename = "LineDtls", skip_serializing_if = "Option::is_none")]
4332    pub line_dtls: Option<Vec<DocumentLineInformation1>>,
4333}
4334
4335impl ReferredDocumentInformation7 {
4336    pub fn validate(&self) -> Result<(), ValidationError> {
4337        if let Some(ref val) = self.tp {
4338            val.validate()?
4339        }
4340        if let Some(ref val) = self.nb {
4341            if val.chars().count() < 1 {
4342                return Err(ValidationError::new(
4343                    1001,
4344                    "nb is shorter than the minimum length of 1".to_string(),
4345                ));
4346            }
4347            if val.chars().count() > 35 {
4348                return Err(ValidationError::new(
4349                    1002,
4350                    "nb exceeds the maximum length of 35".to_string(),
4351                ));
4352            }
4353        }
4354        if let Some(ref vec) = self.line_dtls {
4355            for item in vec {
4356                item.validate()?
4357            }
4358        }
4359        Ok(())
4360    }
4361}
4362
4363// ReferredDocumentType3Choice: Proprietary identification of the type of the remittance document.
4364#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4365pub struct ReferredDocumentType3Choice {
4366    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4367    pub cd: Option<DocumentType6Code>,
4368    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
4369    pub prtry: Option<String>,
4370}
4371
4372impl ReferredDocumentType3Choice {
4373    pub fn validate(&self) -> Result<(), ValidationError> {
4374        if let Some(ref val) = self.cd {
4375            val.validate()?
4376        }
4377        if let Some(ref val) = self.prtry {
4378            if val.chars().count() < 1 {
4379                return Err(ValidationError::new(
4380                    1001,
4381                    "prtry is shorter than the minimum length of 1".to_string(),
4382                ));
4383            }
4384            if val.chars().count() > 35 {
4385                return Err(ValidationError::new(
4386                    1002,
4387                    "prtry exceeds the maximum length of 35".to_string(),
4388                ));
4389            }
4390        }
4391        Ok(())
4392    }
4393}
4394
4395// ReferredDocumentType4: Identification of the issuer of the reference document type.
4396#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4397pub struct ReferredDocumentType4 {
4398    #[serde(rename = "CdOrPrtry")]
4399    pub cd_or_prtry: ReferredDocumentType3Choice,
4400    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
4401    pub issr: Option<String>,
4402}
4403
4404impl ReferredDocumentType4 {
4405    pub fn validate(&self) -> Result<(), ValidationError> {
4406        self.cd_or_prtry.validate()?;
4407        if let Some(ref val) = self.issr {
4408            if val.chars().count() < 1 {
4409                return Err(ValidationError::new(
4410                    1001,
4411                    "issr is shorter than the minimum length of 1".to_string(),
4412                ));
4413            }
4414            if val.chars().count() > 35 {
4415                return Err(ValidationError::new(
4416                    1002,
4417                    "issr exceeds the maximum length of 35".to_string(),
4418                ));
4419            }
4420        }
4421        Ok(())
4422    }
4423}
4424
4425// RegulatoryAuthority2: Country of the entity that requires the regulatory reporting information.
4426#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4427pub struct RegulatoryAuthority2 {
4428    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
4429    pub nm: Option<String>,
4430    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
4431    pub ctry: Option<String>,
4432}
4433
4434impl RegulatoryAuthority2 {
4435    pub fn validate(&self) -> Result<(), ValidationError> {
4436        if let Some(ref val) = self.nm {
4437            if val.chars().count() < 1 {
4438                return Err(ValidationError::new(
4439                    1001,
4440                    "nm is shorter than the minimum length of 1".to_string(),
4441                ));
4442            }
4443            if val.chars().count() > 140 {
4444                return Err(ValidationError::new(
4445                    1002,
4446                    "nm exceeds the maximum length of 140".to_string(),
4447                ));
4448            }
4449        }
4450        if let Some(ref val) = self.ctry {
4451            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
4452            if !pattern.is_match(val) {
4453                return Err(ValidationError::new(
4454                    1005,
4455                    "ctry does not match the required pattern".to_string(),
4456                ));
4457            }
4458        }
4459        Ok(())
4460    }
4461}
4462
4463// RegulatoryReporting3: Set of elements used to provide details on the regulatory reporting information.
4464#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4465pub struct RegulatoryReporting3 {
4466    #[serde(rename = "DbtCdtRptgInd", skip_serializing_if = "Option::is_none")]
4467    pub dbt_cdt_rptg_ind: Option<RegulatoryReportingType1Code>,
4468    #[serde(rename = "Authrty", skip_serializing_if = "Option::is_none")]
4469    pub authrty: Option<RegulatoryAuthority2>,
4470    #[serde(rename = "Dtls", skip_serializing_if = "Option::is_none")]
4471    pub dtls: Option<Vec<StructuredRegulatoryReporting3>>,
4472}
4473
4474impl RegulatoryReporting3 {
4475    pub fn validate(&self) -> Result<(), ValidationError> {
4476        if let Some(ref val) = self.dbt_cdt_rptg_ind {
4477            val.validate()?
4478        }
4479        if let Some(ref val) = self.authrty {
4480            val.validate()?
4481        }
4482        if let Some(ref vec) = self.dtls {
4483            for item in vec {
4484                item.validate()?
4485            }
4486        }
4487        Ok(())
4488    }
4489}
4490
4491// RegulatoryReportingType1Code: Regulatory information applies to both credit and debit sides.
4492#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4493pub enum RegulatoryReportingType1Code {
4494    #[default]
4495    #[serde(rename = "CRED")]
4496    CodeCRED,
4497    #[serde(rename = "DEBT")]
4498    CodeDEBT,
4499    #[serde(rename = "BOTH")]
4500    CodeBOTH,
4501}
4502
4503impl RegulatoryReportingType1Code {
4504    pub fn validate(&self) -> Result<(), ValidationError> {
4505        Ok(())
4506    }
4507}
4508
4509// RemittanceAmount2: Amount of money remitted for the referred document.
4510#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4511pub struct RemittanceAmount2 {
4512    #[serde(rename = "DuePyblAmt", skip_serializing_if = "Option::is_none")]
4513    pub due_pybl_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4514    #[serde(rename = "DscntApldAmt", skip_serializing_if = "Option::is_none")]
4515    pub dscnt_apld_amt: Option<Vec<DiscountAmountAndType1>>,
4516    #[serde(rename = "CdtNoteAmt", skip_serializing_if = "Option::is_none")]
4517    pub cdt_note_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4518    #[serde(rename = "TaxAmt", skip_serializing_if = "Option::is_none")]
4519    pub tax_amt: Option<Vec<TaxAmountAndType1>>,
4520    #[serde(rename = "AdjstmntAmtAndRsn", skip_serializing_if = "Option::is_none")]
4521    pub adjstmnt_amt_and_rsn: Option<Vec<DocumentAdjustment1>>,
4522    #[serde(rename = "RmtdAmt", skip_serializing_if = "Option::is_none")]
4523    pub rmtd_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4524}
4525
4526impl RemittanceAmount2 {
4527    pub fn validate(&self) -> Result<(), ValidationError> {
4528        if let Some(ref val) = self.due_pybl_amt {
4529            val.validate()?
4530        }
4531        if let Some(ref vec) = self.dscnt_apld_amt {
4532            for item in vec {
4533                item.validate()?
4534            }
4535        }
4536        if let Some(ref val) = self.cdt_note_amt {
4537            val.validate()?
4538        }
4539        if let Some(ref vec) = self.tax_amt {
4540            for item in vec {
4541                item.validate()?
4542            }
4543        }
4544        if let Some(ref vec) = self.adjstmnt_amt_and_rsn {
4545            for item in vec {
4546                item.validate()?
4547            }
4548        }
4549        if let Some(ref val) = self.rmtd_amt {
4550            val.validate()?
4551        }
4552        Ok(())
4553    }
4554}
4555
4556// RemittanceAmount3: Amount of money remitted.
4557#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4558pub struct RemittanceAmount3 {
4559    #[serde(rename = "DuePyblAmt", skip_serializing_if = "Option::is_none")]
4560    pub due_pybl_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4561    #[serde(rename = "DscntApldAmt", skip_serializing_if = "Option::is_none")]
4562    pub dscnt_apld_amt: Option<Vec<DiscountAmountAndType1>>,
4563    #[serde(rename = "CdtNoteAmt", skip_serializing_if = "Option::is_none")]
4564    pub cdt_note_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4565    #[serde(rename = "TaxAmt", skip_serializing_if = "Option::is_none")]
4566    pub tax_amt: Option<Vec<TaxAmountAndType1>>,
4567    #[serde(rename = "AdjstmntAmtAndRsn", skip_serializing_if = "Option::is_none")]
4568    pub adjstmnt_amt_and_rsn: Option<Vec<DocumentAdjustment1>>,
4569    #[serde(rename = "RmtdAmt", skip_serializing_if = "Option::is_none")]
4570    pub rmtd_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4571}
4572
4573impl RemittanceAmount3 {
4574    pub fn validate(&self) -> Result<(), ValidationError> {
4575        if let Some(ref val) = self.due_pybl_amt {
4576            val.validate()?
4577        }
4578        if let Some(ref vec) = self.dscnt_apld_amt {
4579            for item in vec {
4580                item.validate()?
4581            }
4582        }
4583        if let Some(ref val) = self.cdt_note_amt {
4584            val.validate()?
4585        }
4586        if let Some(ref vec) = self.tax_amt {
4587            for item in vec {
4588                item.validate()?
4589            }
4590        }
4591        if let Some(ref vec) = self.adjstmnt_amt_and_rsn {
4592            for item in vec {
4593                item.validate()?
4594            }
4595        }
4596        if let Some(ref val) = self.rmtd_amt {
4597            val.validate()?
4598        }
4599        Ok(())
4600    }
4601}
4602
4603// RemittanceInformation161: Information supplied to enable the matching/reconciliation of an entry with the items that the payment is intended to settle, such as commercial invoices in an accounts' receivable system, in a structured form.
4604#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4605pub struct RemittanceInformation161 {
4606    #[serde(rename = "Ustrd", skip_serializing_if = "Option::is_none")]
4607    pub ustrd: Option<String>,
4608    #[serde(rename = "Strd", skip_serializing_if = "Option::is_none")]
4609    pub strd: Option<Vec<StructuredRemittanceInformation161>>,
4610}
4611
4612impl RemittanceInformation161 {
4613    pub fn validate(&self) -> Result<(), ValidationError> {
4614        if let Some(ref val) = self.ustrd {
4615            if val.chars().count() < 1 {
4616                return Err(ValidationError::new(
4617                    1001,
4618                    "ustrd is shorter than the minimum length of 1".to_string(),
4619                ));
4620            }
4621            if val.chars().count() > 140 {
4622                return Err(ValidationError::new(
4623                    1002,
4624                    "ustrd exceeds the maximum length of 140".to_string(),
4625                ));
4626            }
4627        }
4628        if let Some(ref vec) = self.strd {
4629            for item in vec {
4630                item.validate()?
4631            }
4632        }
4633        Ok(())
4634    }
4635}
4636
4637// RemittanceLocation71: Set of elements used to provide information on the location and/or delivery of the remittance information.
4638#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4639pub struct RemittanceLocation71 {
4640    #[serde(rename = "RmtId", skip_serializing_if = "Option::is_none")]
4641    pub rmt_id: Option<String>,
4642    #[serde(rename = "RmtLctnDtls", skip_serializing_if = "Option::is_none")]
4643    pub rmt_lctn_dtls: Option<Vec<RemittanceLocationData11>>,
4644}
4645
4646impl RemittanceLocation71 {
4647    pub fn validate(&self) -> Result<(), ValidationError> {
4648        if let Some(ref val) = self.rmt_id {
4649            if val.chars().count() < 1 {
4650                return Err(ValidationError::new(
4651                    1001,
4652                    "rmt_id is shorter than the minimum length of 1".to_string(),
4653                ));
4654            }
4655            if val.chars().count() > 35 {
4656                return Err(ValidationError::new(
4657                    1002,
4658                    "rmt_id exceeds the maximum length of 35".to_string(),
4659                ));
4660            }
4661        }
4662        if let Some(ref vec) = self.rmt_lctn_dtls {
4663            for item in vec {
4664                item.validate()?
4665            }
4666        }
4667        Ok(())
4668    }
4669}
4670
4671// RemittanceLocationData11: Postal address to which an agent is to send the remittance information.
4672#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4673pub struct RemittanceLocationData11 {
4674    #[serde(rename = "Mtd")]
4675    pub mtd: RemittanceLocationMethod2Code,
4676    #[serde(rename = "ElctrncAdr", skip_serializing_if = "Option::is_none")]
4677    pub elctrnc_adr: Option<String>,
4678    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
4679    pub pstl_adr: Option<NameAndAddress161>,
4680}
4681
4682impl RemittanceLocationData11 {
4683    pub fn validate(&self) -> Result<(), ValidationError> {
4684        self.mtd.validate()?;
4685        if let Some(ref val) = self.elctrnc_adr {
4686            if val.chars().count() < 1 {
4687                return Err(ValidationError::new(
4688                    1001,
4689                    "elctrnc_adr is shorter than the minimum length of 1".to_string(),
4690                ));
4691            }
4692            if val.chars().count() > 2048 {
4693                return Err(ValidationError::new(
4694                    1002,
4695                    "elctrnc_adr exceeds the maximum length of 2048".to_string(),
4696                ));
4697            }
4698        }
4699        if let Some(ref val) = self.pstl_adr {
4700            val.validate()?
4701        }
4702        Ok(())
4703    }
4704}
4705
4706// RemittanceLocationMethod2Code: Remittance advice information must be sent through by phone as a short message service (SMS).
4707#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4708pub enum RemittanceLocationMethod2Code {
4709    #[default]
4710    #[serde(rename = "FAXI")]
4711    CodeFAXI,
4712    #[serde(rename = "EDIC")]
4713    CodeEDIC,
4714    #[serde(rename = "URID")]
4715    CodeURID,
4716    #[serde(rename = "EMAL")]
4717    CodeEMAL,
4718    #[serde(rename = "POST")]
4719    CodePOST,
4720    #[serde(rename = "SMSM")]
4721    CodeSMSM,
4722}
4723
4724impl RemittanceLocationMethod2Code {
4725    pub fn validate(&self) -> Result<(), ValidationError> {
4726        Ok(())
4727    }
4728}
4729
4730// ServiceLevel8Choice: Specifies a pre-agreed service or level of service between the parties, as a proprietary code.
4731#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4732pub struct ServiceLevel8Choice {
4733    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4734    pub cd: Option<String>,
4735    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
4736    pub prtry: Option<String>,
4737}
4738
4739impl ServiceLevel8Choice {
4740    pub fn validate(&self) -> Result<(), ValidationError> {
4741        if let Some(ref val) = self.cd {
4742            if val.chars().count() < 1 {
4743                return Err(ValidationError::new(
4744                    1001,
4745                    "cd is shorter than the minimum length of 1".to_string(),
4746                ));
4747            }
4748            if val.chars().count() > 4 {
4749                return Err(ValidationError::new(
4750                    1002,
4751                    "cd exceeds the maximum length of 4".to_string(),
4752                ));
4753            }
4754        }
4755        if let Some(ref val) = self.prtry {
4756            if val.chars().count() < 1 {
4757                return Err(ValidationError::new(
4758                    1001,
4759                    "prtry is shorter than the minimum length of 1".to_string(),
4760                ));
4761            }
4762            if val.chars().count() > 35 {
4763                return Err(ValidationError::new(
4764                    1002,
4765                    "prtry exceeds the maximum length of 35".to_string(),
4766                ));
4767            }
4768        }
4769        Ok(())
4770    }
4771}
4772
4773// StructuredRegulatoryReporting3: Additional details that cater for specific domestic regulatory requirements.
4774#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4775pub struct StructuredRegulatoryReporting3 {
4776    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
4777    pub tp: Option<String>,
4778    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
4779    pub dt: Option<String>,
4780    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
4781    pub ctry: Option<String>,
4782    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4783    pub cd: Option<String>,
4784    #[serde(rename = "Amt", skip_serializing_if = "Option::is_none")]
4785    pub amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4786    #[serde(rename = "Inf", skip_serializing_if = "Option::is_none")]
4787    pub inf: Option<Vec<String>>,
4788}
4789
4790impl StructuredRegulatoryReporting3 {
4791    pub fn validate(&self) -> Result<(), ValidationError> {
4792        if let Some(ref val) = self.tp {
4793            if val.chars().count() < 1 {
4794                return Err(ValidationError::new(
4795                    1001,
4796                    "tp is shorter than the minimum length of 1".to_string(),
4797                ));
4798            }
4799            if val.chars().count() > 35 {
4800                return Err(ValidationError::new(
4801                    1002,
4802                    "tp exceeds the maximum length of 35".to_string(),
4803                ));
4804            }
4805        }
4806        if let Some(ref val) = self.ctry {
4807            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
4808            if !pattern.is_match(val) {
4809                return Err(ValidationError::new(
4810                    1005,
4811                    "ctry does not match the required pattern".to_string(),
4812                ));
4813            }
4814        }
4815        if let Some(ref val) = self.cd {
4816            if val.chars().count() < 1 {
4817                return Err(ValidationError::new(
4818                    1001,
4819                    "cd is shorter than the minimum length of 1".to_string(),
4820                ));
4821            }
4822            if val.chars().count() > 10 {
4823                return Err(ValidationError::new(
4824                    1002,
4825                    "cd exceeds the maximum length of 10".to_string(),
4826                ));
4827            }
4828        }
4829        if let Some(ref val) = self.amt {
4830            val.validate()?
4831        }
4832        if let Some(ref vec) = self.inf {
4833            for item in vec {
4834                if item.chars().count() < 1 {
4835                    return Err(ValidationError::new(
4836                        1001,
4837                        "inf is shorter than the minimum length of 1".to_string(),
4838                    ));
4839                }
4840                if item.chars().count() > 35 {
4841                    return Err(ValidationError::new(
4842                        1002,
4843                        "inf exceeds the maximum length of 35".to_string(),
4844                    ));
4845                }
4846            }
4847        }
4848        Ok(())
4849    }
4850}
4851
4852// StructuredRemittanceInformation161: Additional information, in free text form, to complement the structured remittance information.
4853#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4854pub struct StructuredRemittanceInformation161 {
4855    #[serde(rename = "RfrdDocInf", skip_serializing_if = "Option::is_none")]
4856    pub rfrd_doc_inf: Option<Vec<ReferredDocumentInformation7>>,
4857    #[serde(rename = "RfrdDocAmt", skip_serializing_if = "Option::is_none")]
4858    pub rfrd_doc_amt: Option<RemittanceAmount2>,
4859    #[serde(rename = "CdtrRefInf", skip_serializing_if = "Option::is_none")]
4860    pub cdtr_ref_inf: Option<CreditorReferenceInformation2>,
4861    #[serde(rename = "Invcr", skip_serializing_if = "Option::is_none")]
4862    pub invcr: Option<PartyIdentification1353>,
4863    #[serde(rename = "Invcee", skip_serializing_if = "Option::is_none")]
4864    pub invcee: Option<PartyIdentification1353>,
4865    #[serde(rename = "TaxRmt", skip_serializing_if = "Option::is_none")]
4866    pub tax_rmt: Option<TaxInformation7>,
4867    #[serde(rename = "GrnshmtRmt", skip_serializing_if = "Option::is_none")]
4868    pub grnshmt_rmt: Option<Garnishment31>,
4869    #[serde(rename = "AddtlRmtInf", skip_serializing_if = "Option::is_none")]
4870    pub addtl_rmt_inf: Option<Vec<String>>,
4871}
4872
4873impl StructuredRemittanceInformation161 {
4874    pub fn validate(&self) -> Result<(), ValidationError> {
4875        if let Some(ref vec) = self.rfrd_doc_inf {
4876            for item in vec {
4877                item.validate()?
4878            }
4879        }
4880        if let Some(ref val) = self.rfrd_doc_amt {
4881            val.validate()?
4882        }
4883        if let Some(ref val) = self.cdtr_ref_inf {
4884            val.validate()?
4885        }
4886        if let Some(ref val) = self.invcr {
4887            val.validate()?
4888        }
4889        if let Some(ref val) = self.invcee {
4890            val.validate()?
4891        }
4892        if let Some(ref val) = self.tax_rmt {
4893            val.validate()?
4894        }
4895        if let Some(ref val) = self.grnshmt_rmt {
4896            val.validate()?
4897        }
4898        if let Some(ref vec) = self.addtl_rmt_inf {
4899            for item in vec {
4900                if item.chars().count() < 1 {
4901                    return Err(ValidationError::new(
4902                        1001,
4903                        "addtl_rmt_inf is shorter than the minimum length of 1".to_string(),
4904                    ));
4905                }
4906                if item.chars().count() > 140 {
4907                    return Err(ValidationError::new(
4908                        1002,
4909                        "addtl_rmt_inf exceeds the maximum length of 140".to_string(),
4910                    ));
4911                }
4912            }
4913        }
4914        Ok(())
4915    }
4916}
4917
4918// TaxAmount2: Set of elements used to provide details on the tax period and amount.
4919#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4920pub struct TaxAmount2 {
4921    #[serde(rename = "Rate", skip_serializing_if = "Option::is_none")]
4922    pub rate: Option<f64>,
4923    #[serde(rename = "TaxblBaseAmt", skip_serializing_if = "Option::is_none")]
4924    pub taxbl_base_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4925    #[serde(rename = "TtlAmt", skip_serializing_if = "Option::is_none")]
4926    pub ttl_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
4927    #[serde(rename = "Dtls", skip_serializing_if = "Option::is_none")]
4928    pub dtls: Option<Vec<TaxRecordDetails2>>,
4929}
4930
4931impl TaxAmount2 {
4932    pub fn validate(&self) -> Result<(), ValidationError> {
4933        if let Some(ref val) = self.taxbl_base_amt {
4934            val.validate()?
4935        }
4936        if let Some(ref val) = self.ttl_amt {
4937            val.validate()?
4938        }
4939        if let Some(ref vec) = self.dtls {
4940            for item in vec {
4941                item.validate()?
4942            }
4943        }
4944        Ok(())
4945    }
4946}
4947
4948// TaxAmountAndType1: Amount of money, which has been typed.
4949#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4950pub struct TaxAmountAndType1 {
4951    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
4952    pub tp: Option<TaxAmountType1Choice>,
4953    #[serde(rename = "Amt")]
4954    pub amt: ActiveOrHistoricCurrencyAndAmount,
4955}
4956
4957impl TaxAmountAndType1 {
4958    pub fn validate(&self) -> Result<(), ValidationError> {
4959        if let Some(ref val) = self.tp {
4960            val.validate()?
4961        }
4962        self.amt.validate()?;
4963        Ok(())
4964    }
4965}
4966
4967// TaxAmountType1Choice: Specifies the amount type, in a free-text form.
4968#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
4969pub struct TaxAmountType1Choice {
4970    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
4971    pub cd: Option<String>,
4972    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
4973    pub prtry: Option<String>,
4974}
4975
4976impl TaxAmountType1Choice {
4977    pub fn validate(&self) -> Result<(), ValidationError> {
4978        if let Some(ref val) = self.cd {
4979            if val.chars().count() < 1 {
4980                return Err(ValidationError::new(
4981                    1001,
4982                    "cd is shorter than the minimum length of 1".to_string(),
4983                ));
4984            }
4985            if val.chars().count() > 4 {
4986                return Err(ValidationError::new(
4987                    1002,
4988                    "cd exceeds the maximum length of 4".to_string(),
4989                ));
4990            }
4991        }
4992        if let Some(ref val) = self.prtry {
4993            if val.chars().count() < 1 {
4994                return Err(ValidationError::new(
4995                    1001,
4996                    "prtry is shorter than the minimum length of 1".to_string(),
4997                ));
4998            }
4999            if val.chars().count() > 35 {
5000                return Err(ValidationError::new(
5001                    1002,
5002                    "prtry exceeds the maximum length of 35".to_string(),
5003                ));
5004            }
5005        }
5006        Ok(())
5007    }
5008}
5009
5010// TaxAuthorisation1: Name of the debtor or the debtor's authorised representative.
5011#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5012pub struct TaxAuthorisation1 {
5013    #[serde(rename = "Titl", skip_serializing_if = "Option::is_none")]
5014    pub titl: Option<String>,
5015    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
5016    pub nm: Option<String>,
5017}
5018
5019impl TaxAuthorisation1 {
5020    pub fn validate(&self) -> Result<(), ValidationError> {
5021        if let Some(ref val) = self.titl {
5022            if val.chars().count() < 1 {
5023                return Err(ValidationError::new(
5024                    1001,
5025                    "titl is shorter than the minimum length of 1".to_string(),
5026                ));
5027            }
5028            if val.chars().count() > 35 {
5029                return Err(ValidationError::new(
5030                    1002,
5031                    "titl exceeds the maximum length of 35".to_string(),
5032                ));
5033            }
5034        }
5035        if let Some(ref val) = self.nm {
5036            if val.chars().count() < 1 {
5037                return Err(ValidationError::new(
5038                    1001,
5039                    "nm is shorter than the minimum length of 1".to_string(),
5040                ));
5041            }
5042            if val.chars().count() > 140 {
5043                return Err(ValidationError::new(
5044                    1002,
5045                    "nm exceeds the maximum length of 140".to_string(),
5046                ));
5047            }
5048        }
5049        Ok(())
5050    }
5051}
5052
5053// TaxInformation7: Record of tax details.
5054#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5055pub struct TaxInformation7 {
5056    #[serde(rename = "Cdtr", skip_serializing_if = "Option::is_none")]
5057    pub cdtr: Option<TaxParty1>,
5058    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
5059    pub dbtr: Option<TaxParty2>,
5060    #[serde(rename = "UltmtDbtr", skip_serializing_if = "Option::is_none")]
5061    pub ultmt_dbtr: Option<TaxParty2>,
5062    #[serde(rename = "AdmstnZone", skip_serializing_if = "Option::is_none")]
5063    pub admstn_zone: Option<String>,
5064    #[serde(rename = "RefNb", skip_serializing_if = "Option::is_none")]
5065    pub ref_nb: Option<String>,
5066    #[serde(rename = "Mtd", skip_serializing_if = "Option::is_none")]
5067    pub mtd: Option<String>,
5068    #[serde(rename = "TtlTaxblBaseAmt", skip_serializing_if = "Option::is_none")]
5069    pub ttl_taxbl_base_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
5070    #[serde(rename = "TtlTaxAmt", skip_serializing_if = "Option::is_none")]
5071    pub ttl_tax_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
5072    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
5073    pub dt: Option<String>,
5074    #[serde(rename = "SeqNb", skip_serializing_if = "Option::is_none")]
5075    pub seq_nb: Option<f64>,
5076    #[serde(rename = "Rcrd", skip_serializing_if = "Option::is_none")]
5077    pub rcrd: Option<Vec<TaxRecord2>>,
5078}
5079
5080impl TaxInformation7 {
5081    pub fn validate(&self) -> Result<(), ValidationError> {
5082        if let Some(ref val) = self.cdtr {
5083            val.validate()?
5084        }
5085        if let Some(ref val) = self.dbtr {
5086            val.validate()?
5087        }
5088        if let Some(ref val) = self.ultmt_dbtr {
5089            val.validate()?
5090        }
5091        if let Some(ref val) = self.admstn_zone {
5092            if val.chars().count() < 1 {
5093                return Err(ValidationError::new(
5094                    1001,
5095                    "admstn_zone is shorter than the minimum length of 1".to_string(),
5096                ));
5097            }
5098            if val.chars().count() > 35 {
5099                return Err(ValidationError::new(
5100                    1002,
5101                    "admstn_zone exceeds the maximum length of 35".to_string(),
5102                ));
5103            }
5104        }
5105        if let Some(ref val) = self.ref_nb {
5106            if val.chars().count() < 1 {
5107                return Err(ValidationError::new(
5108                    1001,
5109                    "ref_nb is shorter than the minimum length of 1".to_string(),
5110                ));
5111            }
5112            if val.chars().count() > 140 {
5113                return Err(ValidationError::new(
5114                    1002,
5115                    "ref_nb exceeds the maximum length of 140".to_string(),
5116                ));
5117            }
5118        }
5119        if let Some(ref val) = self.mtd {
5120            if val.chars().count() < 1 {
5121                return Err(ValidationError::new(
5122                    1001,
5123                    "mtd is shorter than the minimum length of 1".to_string(),
5124                ));
5125            }
5126            if val.chars().count() > 35 {
5127                return Err(ValidationError::new(
5128                    1002,
5129                    "mtd exceeds the maximum length of 35".to_string(),
5130                ));
5131            }
5132        }
5133        if let Some(ref val) = self.ttl_taxbl_base_amt {
5134            val.validate()?
5135        }
5136        if let Some(ref val) = self.ttl_tax_amt {
5137            val.validate()?
5138        }
5139        if let Some(ref vec) = self.rcrd {
5140            for item in vec {
5141                item.validate()?
5142            }
5143        }
5144        Ok(())
5145    }
5146}
5147
5148// TaxInformation8: Record of tax details.
5149#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5150pub struct TaxInformation8 {
5151    #[serde(rename = "Cdtr", skip_serializing_if = "Option::is_none")]
5152    pub cdtr: Option<TaxParty1>,
5153    #[serde(rename = "Dbtr", skip_serializing_if = "Option::is_none")]
5154    pub dbtr: Option<TaxParty2>,
5155    #[serde(rename = "AdmstnZone", skip_serializing_if = "Option::is_none")]
5156    pub admstn_zone: Option<String>,
5157    #[serde(rename = "RefNb", skip_serializing_if = "Option::is_none")]
5158    pub ref_nb: Option<String>,
5159    #[serde(rename = "Mtd", skip_serializing_if = "Option::is_none")]
5160    pub mtd: Option<String>,
5161    #[serde(rename = "TtlTaxblBaseAmt", skip_serializing_if = "Option::is_none")]
5162    pub ttl_taxbl_base_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
5163    #[serde(rename = "TtlTaxAmt", skip_serializing_if = "Option::is_none")]
5164    pub ttl_tax_amt: Option<ActiveOrHistoricCurrencyAndAmount>,
5165    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
5166    pub dt: Option<String>,
5167    #[serde(rename = "SeqNb", skip_serializing_if = "Option::is_none")]
5168    pub seq_nb: Option<f64>,
5169    #[serde(rename = "Rcrd", skip_serializing_if = "Option::is_none")]
5170    pub rcrd: Option<Vec<TaxRecord2>>,
5171}
5172
5173impl TaxInformation8 {
5174    pub fn validate(&self) -> Result<(), ValidationError> {
5175        if let Some(ref val) = self.cdtr {
5176            val.validate()?
5177        }
5178        if let Some(ref val) = self.dbtr {
5179            val.validate()?
5180        }
5181        if let Some(ref val) = self.admstn_zone {
5182            if val.chars().count() < 1 {
5183                return Err(ValidationError::new(
5184                    1001,
5185                    "admstn_zone is shorter than the minimum length of 1".to_string(),
5186                ));
5187            }
5188            if val.chars().count() > 35 {
5189                return Err(ValidationError::new(
5190                    1002,
5191                    "admstn_zone exceeds the maximum length of 35".to_string(),
5192                ));
5193            }
5194        }
5195        if let Some(ref val) = self.ref_nb {
5196            if val.chars().count() < 1 {
5197                return Err(ValidationError::new(
5198                    1001,
5199                    "ref_nb is shorter than the minimum length of 1".to_string(),
5200                ));
5201            }
5202            if val.chars().count() > 140 {
5203                return Err(ValidationError::new(
5204                    1002,
5205                    "ref_nb exceeds the maximum length of 140".to_string(),
5206                ));
5207            }
5208        }
5209        if let Some(ref val) = self.mtd {
5210            if val.chars().count() < 1 {
5211                return Err(ValidationError::new(
5212                    1001,
5213                    "mtd is shorter than the minimum length of 1".to_string(),
5214                ));
5215            }
5216            if val.chars().count() > 35 {
5217                return Err(ValidationError::new(
5218                    1002,
5219                    "mtd exceeds the maximum length of 35".to_string(),
5220                ));
5221            }
5222        }
5223        if let Some(ref val) = self.ttl_taxbl_base_amt {
5224            val.validate()?
5225        }
5226        if let Some(ref val) = self.ttl_tax_amt {
5227            val.validate()?
5228        }
5229        if let Some(ref vec) = self.rcrd {
5230            for item in vec {
5231                item.validate()?
5232            }
5233        }
5234        Ok(())
5235    }
5236}
5237
5238// TaxParty1: Type of tax payer.
5239#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5240pub struct TaxParty1 {
5241    #[serde(rename = "TaxId", skip_serializing_if = "Option::is_none")]
5242    pub tax_id: Option<String>,
5243    #[serde(rename = "RegnId", skip_serializing_if = "Option::is_none")]
5244    pub regn_id: Option<String>,
5245    #[serde(rename = "TaxTp", skip_serializing_if = "Option::is_none")]
5246    pub tax_tp: Option<String>,
5247}
5248
5249impl TaxParty1 {
5250    pub fn validate(&self) -> Result<(), ValidationError> {
5251        if let Some(ref val) = self.tax_id {
5252            if val.chars().count() < 1 {
5253                return Err(ValidationError::new(
5254                    1001,
5255                    "tax_id is shorter than the minimum length of 1".to_string(),
5256                ));
5257            }
5258            if val.chars().count() > 35 {
5259                return Err(ValidationError::new(
5260                    1002,
5261                    "tax_id exceeds the maximum length of 35".to_string(),
5262                ));
5263            }
5264        }
5265        if let Some(ref val) = self.regn_id {
5266            if val.chars().count() < 1 {
5267                return Err(ValidationError::new(
5268                    1001,
5269                    "regn_id is shorter than the minimum length of 1".to_string(),
5270                ));
5271            }
5272            if val.chars().count() > 35 {
5273                return Err(ValidationError::new(
5274                    1002,
5275                    "regn_id exceeds the maximum length of 35".to_string(),
5276                ));
5277            }
5278        }
5279        if let Some(ref val) = self.tax_tp {
5280            if val.chars().count() < 1 {
5281                return Err(ValidationError::new(
5282                    1001,
5283                    "tax_tp is shorter than the minimum length of 1".to_string(),
5284                ));
5285            }
5286            if val.chars().count() > 35 {
5287                return Err(ValidationError::new(
5288                    1002,
5289                    "tax_tp exceeds the maximum length of 35".to_string(),
5290                ));
5291            }
5292        }
5293        Ok(())
5294    }
5295}
5296
5297// TaxParty2: Details of the authorised tax paying party.
5298#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5299pub struct TaxParty2 {
5300    #[serde(rename = "TaxId", skip_serializing_if = "Option::is_none")]
5301    pub tax_id: Option<String>,
5302    #[serde(rename = "RegnId", skip_serializing_if = "Option::is_none")]
5303    pub regn_id: Option<String>,
5304    #[serde(rename = "TaxTp", skip_serializing_if = "Option::is_none")]
5305    pub tax_tp: Option<String>,
5306    #[serde(rename = "Authstn", skip_serializing_if = "Option::is_none")]
5307    pub authstn: Option<TaxAuthorisation1>,
5308}
5309
5310impl TaxParty2 {
5311    pub fn validate(&self) -> Result<(), ValidationError> {
5312        if let Some(ref val) = self.tax_id {
5313            if val.chars().count() < 1 {
5314                return Err(ValidationError::new(
5315                    1001,
5316                    "tax_id is shorter than the minimum length of 1".to_string(),
5317                ));
5318            }
5319            if val.chars().count() > 35 {
5320                return Err(ValidationError::new(
5321                    1002,
5322                    "tax_id exceeds the maximum length of 35".to_string(),
5323                ));
5324            }
5325        }
5326        if let Some(ref val) = self.regn_id {
5327            if val.chars().count() < 1 {
5328                return Err(ValidationError::new(
5329                    1001,
5330                    "regn_id is shorter than the minimum length of 1".to_string(),
5331                ));
5332            }
5333            if val.chars().count() > 35 {
5334                return Err(ValidationError::new(
5335                    1002,
5336                    "regn_id exceeds the maximum length of 35".to_string(),
5337                ));
5338            }
5339        }
5340        if let Some(ref val) = self.tax_tp {
5341            if val.chars().count() < 1 {
5342                return Err(ValidationError::new(
5343                    1001,
5344                    "tax_tp is shorter than the minimum length of 1".to_string(),
5345                ));
5346            }
5347            if val.chars().count() > 35 {
5348                return Err(ValidationError::new(
5349                    1002,
5350                    "tax_tp exceeds the maximum length of 35".to_string(),
5351                ));
5352            }
5353        }
5354        if let Some(ref val) = self.authstn {
5355            val.validate()?
5356        }
5357        Ok(())
5358    }
5359}
5360
5361// TaxPeriod2: Range of time between a start date and an end date for which the tax report is provided.
5362#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5363pub struct TaxPeriod2 {
5364    #[serde(rename = "Yr", skip_serializing_if = "Option::is_none")]
5365    pub yr: Option<String>,
5366    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
5367    pub tp: Option<TaxRecordPeriod1Code>,
5368    #[serde(rename = "FrToDt", skip_serializing_if = "Option::is_none")]
5369    pub fr_to_dt: Option<DatePeriod2>,
5370}
5371
5372impl TaxPeriod2 {
5373    pub fn validate(&self) -> Result<(), ValidationError> {
5374        if let Some(ref val) = self.tp {
5375            val.validate()?
5376        }
5377        if let Some(ref val) = self.fr_to_dt {
5378            val.validate()?
5379        }
5380        Ok(())
5381    }
5382}
5383
5384// TaxRecord2: Further details of the tax record.
5385#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5386pub struct TaxRecord2 {
5387    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
5388    pub tp: Option<String>,
5389    #[serde(rename = "Ctgy", skip_serializing_if = "Option::is_none")]
5390    pub ctgy: Option<String>,
5391    #[serde(rename = "CtgyDtls", skip_serializing_if = "Option::is_none")]
5392    pub ctgy_dtls: Option<String>,
5393    #[serde(rename = "DbtrSts", skip_serializing_if = "Option::is_none")]
5394    pub dbtr_sts: Option<String>,
5395    #[serde(rename = "CertId", skip_serializing_if = "Option::is_none")]
5396    pub cert_id: Option<String>,
5397    #[serde(rename = "FrmsCd", skip_serializing_if = "Option::is_none")]
5398    pub frms_cd: Option<String>,
5399    #[serde(rename = "Prd", skip_serializing_if = "Option::is_none")]
5400    pub prd: Option<TaxPeriod2>,
5401    #[serde(rename = "TaxAmt", skip_serializing_if = "Option::is_none")]
5402    pub tax_amt: Option<TaxAmount2>,
5403    #[serde(rename = "AddtlInf", skip_serializing_if = "Option::is_none")]
5404    pub addtl_inf: Option<String>,
5405}
5406
5407impl TaxRecord2 {
5408    pub fn validate(&self) -> Result<(), ValidationError> {
5409        if let Some(ref val) = self.tp {
5410            if val.chars().count() < 1 {
5411                return Err(ValidationError::new(
5412                    1001,
5413                    "tp is shorter than the minimum length of 1".to_string(),
5414                ));
5415            }
5416            if val.chars().count() > 35 {
5417                return Err(ValidationError::new(
5418                    1002,
5419                    "tp exceeds the maximum length of 35".to_string(),
5420                ));
5421            }
5422        }
5423        if let Some(ref val) = self.ctgy {
5424            if val.chars().count() < 1 {
5425                return Err(ValidationError::new(
5426                    1001,
5427                    "ctgy is shorter than the minimum length of 1".to_string(),
5428                ));
5429            }
5430            if val.chars().count() > 35 {
5431                return Err(ValidationError::new(
5432                    1002,
5433                    "ctgy exceeds the maximum length of 35".to_string(),
5434                ));
5435            }
5436        }
5437        if let Some(ref val) = self.ctgy_dtls {
5438            if val.chars().count() < 1 {
5439                return Err(ValidationError::new(
5440                    1001,
5441                    "ctgy_dtls is shorter than the minimum length of 1".to_string(),
5442                ));
5443            }
5444            if val.chars().count() > 35 {
5445                return Err(ValidationError::new(
5446                    1002,
5447                    "ctgy_dtls exceeds the maximum length of 35".to_string(),
5448                ));
5449            }
5450        }
5451        if let Some(ref val) = self.dbtr_sts {
5452            if val.chars().count() < 1 {
5453                return Err(ValidationError::new(
5454                    1001,
5455                    "dbtr_sts is shorter than the minimum length of 1".to_string(),
5456                ));
5457            }
5458            if val.chars().count() > 35 {
5459                return Err(ValidationError::new(
5460                    1002,
5461                    "dbtr_sts exceeds the maximum length of 35".to_string(),
5462                ));
5463            }
5464        }
5465        if let Some(ref val) = self.cert_id {
5466            if val.chars().count() < 1 {
5467                return Err(ValidationError::new(
5468                    1001,
5469                    "cert_id is shorter than the minimum length of 1".to_string(),
5470                ));
5471            }
5472            if val.chars().count() > 35 {
5473                return Err(ValidationError::new(
5474                    1002,
5475                    "cert_id exceeds the maximum length of 35".to_string(),
5476                ));
5477            }
5478        }
5479        if let Some(ref val) = self.frms_cd {
5480            if val.chars().count() < 1 {
5481                return Err(ValidationError::new(
5482                    1001,
5483                    "frms_cd is shorter than the minimum length of 1".to_string(),
5484                ));
5485            }
5486            if val.chars().count() > 35 {
5487                return Err(ValidationError::new(
5488                    1002,
5489                    "frms_cd exceeds the maximum length of 35".to_string(),
5490                ));
5491            }
5492        }
5493        if let Some(ref val) = self.prd {
5494            val.validate()?
5495        }
5496        if let Some(ref val) = self.tax_amt {
5497            val.validate()?
5498        }
5499        if let Some(ref val) = self.addtl_inf {
5500            if val.chars().count() < 1 {
5501                return Err(ValidationError::new(
5502                    1001,
5503                    "addtl_inf is shorter than the minimum length of 1".to_string(),
5504                ));
5505            }
5506            if val.chars().count() > 140 {
5507                return Err(ValidationError::new(
5508                    1002,
5509                    "addtl_inf exceeds the maximum length of 140".to_string(),
5510                ));
5511            }
5512        }
5513        Ok(())
5514    }
5515}
5516
5517// TaxRecordDetails2: Underlying tax amount related to the specified period.
5518#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5519pub struct TaxRecordDetails2 {
5520    #[serde(rename = "Prd", skip_serializing_if = "Option::is_none")]
5521    pub prd: Option<TaxPeriod2>,
5522    #[serde(rename = "Amt")]
5523    pub amt: ActiveOrHistoricCurrencyAndAmount,
5524}
5525
5526impl TaxRecordDetails2 {
5527    pub fn validate(&self) -> Result<(), ValidationError> {
5528        if let Some(ref val) = self.prd {
5529            val.validate()?
5530        }
5531        self.amt.validate()?;
5532        Ok(())
5533    }
5534}
5535
5536// TaxRecordPeriod1Code: Tax is related to the second half of the period.
5537#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
5538pub enum TaxRecordPeriod1Code {
5539    #[default]
5540    #[serde(rename = "MM01")]
5541    CodeMM01,
5542    #[serde(rename = "MM02")]
5543    CodeMM02,
5544    #[serde(rename = "MM03")]
5545    CodeMM03,
5546    #[serde(rename = "MM04")]
5547    CodeMM04,
5548    #[serde(rename = "MM05")]
5549    CodeMM05,
5550    #[serde(rename = "MM06")]
5551    CodeMM06,
5552    #[serde(rename = "MM07")]
5553    CodeMM07,
5554    #[serde(rename = "MM08")]
5555    CodeMM08,
5556    #[serde(rename = "MM09")]
5557    CodeMM09,
5558    #[serde(rename = "MM10")]
5559    CodeMM10,
5560    #[serde(rename = "MM11")]
5561    CodeMM11,
5562    #[serde(rename = "MM12")]
5563    CodeMM12,
5564    #[serde(rename = "QTR1")]
5565    CodeQTR1,
5566    #[serde(rename = "QTR2")]
5567    CodeQTR2,
5568    #[serde(rename = "QTR3")]
5569    CodeQTR3,
5570    #[serde(rename = "QTR4")]
5571    CodeQTR4,
5572    #[serde(rename = "HLF1")]
5573    CodeHLF1,
5574    #[serde(rename = "HLF2")]
5575    CodeHLF2,
5576}
5577
5578impl TaxRecordPeriod1Code {
5579    pub fn validate(&self) -> Result<(), ValidationError> {
5580        Ok(())
5581    }
5582}