mx_message/document/
pacs_008_001_08_stp.rs

1// Plasmatic MX Message Parsing Library
2// https://github.com/GoPlasmatic/MXMessage
3//
4// Copyright (c) 2025 Plasmatic
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// You may obtain a copy of this library at
18// https://github.com/GoPlasmatic/MXMessage
19
20use crate::error::*;
21use regex::Regex;
22use serde::{Deserialize, Serialize};
23
24// AccountIdentification4Choice1: Unique identification of an account, as assigned by the account servicer, using an identification scheme.
25#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
26pub struct AccountIdentification4Choice1 {
27    #[serde(rename = "IBAN", skip_serializing_if = "Option::is_none")]
28    pub iban: Option<String>,
29    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
30    pub othr: Option<GenericAccountIdentification11>,
31}
32
33impl AccountIdentification4Choice1 {
34    pub fn validate(&self) -> Result<(), ValidationError> {
35        if let Some(ref val) = self.iban {
36            let pattern = Regex::new("[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}").unwrap();
37            if !pattern.is_match(val) {
38                return Err(ValidationError::new(
39                    1005,
40                    "iban does not match the required pattern".to_string(),
41                ));
42            }
43        }
44        if let Some(ref val) = self.othr {
45            val.validate()?
46        }
47        Ok(())
48    }
49}
50
51// AccountSchemeName1Choice1: Name of the identification scheme, in a free text form.
52#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
53pub struct AccountSchemeName1Choice1 {
54    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
55    pub cd: Option<String>,
56    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
57    pub prtry: Option<String>,
58}
59
60impl AccountSchemeName1Choice1 {
61    pub fn validate(&self) -> Result<(), ValidationError> {
62        if let Some(ref val) = self.cd {
63            if val.chars().count() < 1 {
64                return Err(ValidationError::new(
65                    1001,
66                    "cd is shorter than the minimum length of 1".to_string(),
67                ));
68            }
69            if val.chars().count() > 4 {
70                return Err(ValidationError::new(
71                    1002,
72                    "cd exceeds the maximum length of 4".to_string(),
73                ));
74            }
75        }
76        if let Some(ref val) = self.prtry {
77            if val.chars().count() < 1 {
78                return Err(ValidationError::new(
79                    1001,
80                    "prtry is shorter than the minimum length of 1".to_string(),
81                ));
82            }
83            if val.chars().count() > 35 {
84                return Err(ValidationError::new(
85                    1002,
86                    "prtry exceeds the maximum length of 35".to_string(),
87                ));
88            }
89            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
90            if !pattern.is_match(val) {
91                return Err(ValidationError::new(
92                    1005,
93                    "prtry does not match the required pattern".to_string(),
94                ));
95            }
96        }
97        Ok(())
98    }
99}
100
101// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
102#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
103pub struct BranchAndFinancialInstitutionIdentification61 {
104    #[serde(rename = "FinInstnId")]
105    pub fin_instn_id: FinancialInstitutionIdentification181,
106}
107
108impl BranchAndFinancialInstitutionIdentification61 {
109    pub fn validate(&self) -> Result<(), ValidationError> {
110        self.fin_instn_id.validate()?;
111        Ok(())
112    }
113}
114
115// CBPRAmount1: CBPR_Amount__1
116#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
117pub struct CBPRAmount1 {
118    #[serde(rename = "@Ccy")]
119    pub ccy: String,
120    #[serde(rename = "$value")]
121    pub value: f64,
122}
123
124impl CBPRAmount1 {
125    pub fn validate(&self) -> Result<(), ValidationError> {
126        Ok(())
127    }
128}
129
130// CashAccount381: Specifies an alternate assumed name for the identification of the account.
131#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
132pub struct CashAccount381 {
133    #[serde(rename = "Id")]
134    pub id: AccountIdentification4Choice1,
135    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
136    pub tp: Option<CashAccountType2Choice1>,
137    #[serde(rename = "Ccy", skip_serializing_if = "Option::is_none")]
138    pub ccy: Option<String>,
139    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
140    pub nm: Option<String>,
141    #[serde(rename = "Prxy", skip_serializing_if = "Option::is_none")]
142    pub prxy: Option<ProxyAccountIdentification11>,
143}
144
145impl CashAccount381 {
146    pub fn validate(&self) -> Result<(), ValidationError> {
147        self.id.validate()?;
148        if let Some(ref val) = self.tp {
149            val.validate()?
150        }
151        if let Some(ref val) = self.ccy {
152            let pattern = Regex::new("[A-Z]{3,3}").unwrap();
153            if !pattern.is_match(val) {
154                return Err(ValidationError::new(
155                    1005,
156                    "ccy does not match the required pattern".to_string(),
157                ));
158            }
159        }
160        if let Some(ref val) = self.nm {
161            if val.chars().count() < 1 {
162                return Err(ValidationError::new(
163                    1001,
164                    "nm is shorter than the minimum length of 1".to_string(),
165                ));
166            }
167            if val.chars().count() > 70 {
168                return Err(ValidationError::new(
169                    1002,
170                    "nm exceeds the maximum length of 70".to_string(),
171                ));
172            }
173            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
174            if !pattern.is_match(val) {
175                return Err(ValidationError::new(
176                    1005,
177                    "nm does not match the required pattern".to_string(),
178                ));
179            }
180        }
181        if let Some(ref val) = self.prxy {
182            val.validate()?
183        }
184        Ok(())
185    }
186}
187
188// CashAccountType2Choice1: Nature or use of the account in a proprietary form.
189#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
190pub struct CashAccountType2Choice1 {
191    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
192    pub cd: Option<String>,
193    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
194    pub prtry: Option<String>,
195}
196
197impl CashAccountType2Choice1 {
198    pub fn validate(&self) -> Result<(), ValidationError> {
199        if let Some(ref val) = self.cd {
200            if val.chars().count() < 1 {
201                return Err(ValidationError::new(
202                    1001,
203                    "cd is shorter than the minimum length of 1".to_string(),
204                ));
205            }
206            if val.chars().count() > 4 {
207                return Err(ValidationError::new(
208                    1002,
209                    "cd exceeds the maximum length of 4".to_string(),
210                ));
211            }
212        }
213        if let Some(ref val) = self.prtry {
214            if val.chars().count() < 1 {
215                return Err(ValidationError::new(
216                    1001,
217                    "prtry is shorter than the minimum length of 1".to_string(),
218                ));
219            }
220            if val.chars().count() > 35 {
221                return Err(ValidationError::new(
222                    1002,
223                    "prtry exceeds the maximum length of 35".to_string(),
224                ));
225            }
226            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
227            if !pattern.is_match(val) {
228                return Err(ValidationError::new(
229                    1005,
230                    "prtry does not match the required pattern".to_string(),
231                ));
232            }
233        }
234        Ok(())
235    }
236}
237
238// CategoryPurpose1Choice1: Category purpose, as published in an external category purpose code list.
239#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
240pub struct CategoryPurpose1Choice1 {
241    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
242    pub cd: Option<String>,
243}
244
245impl CategoryPurpose1Choice1 {
246    pub fn validate(&self) -> Result<(), ValidationError> {
247        if let Some(ref val) = self.cd {
248            if val.chars().count() < 1 {
249                return Err(ValidationError::new(
250                    1001,
251                    "cd is shorter than the minimum length of 1".to_string(),
252                ));
253            }
254            if val.chars().count() > 4 {
255                return Err(ValidationError::new(
256                    1002,
257                    "cd exceeds the maximum length of 4".to_string(),
258                ));
259            }
260        }
261        Ok(())
262    }
263}
264
265// 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.
266#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
267pub enum ChargeBearerType1Code1 {
268    #[default]
269    #[serde(rename = "DEBT")]
270    CodeDEBT,
271    #[serde(rename = "CRED")]
272    CodeCRED,
273    #[serde(rename = "SHAR")]
274    CodeSHAR,
275}
276
277impl ChargeBearerType1Code1 {
278    pub fn validate(&self) -> Result<(), ValidationError> {
279        Ok(())
280    }
281}
282
283// Charges71: Agent that takes the transaction charges or to which the transaction charges are due.
284#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
285pub struct Charges71 {
286    #[serde(rename = "Amt")]
287    pub amt: CBPRAmount1,
288    #[serde(rename = "Agt")]
289    pub agt: BranchAndFinancialInstitutionIdentification61,
290}
291
292impl Charges71 {
293    pub fn validate(&self) -> Result<(), ValidationError> {
294        self.amt.validate()?;
295        self.agt.validate()?;
296        Ok(())
297    }
298}
299
300// ClearingChannel2Code: Payment through internal book transfer.
301#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
302pub enum ClearingChannel2Code {
303    #[default]
304    #[serde(rename = "RTGS")]
305    CodeRTGS,
306    #[serde(rename = "RTNS")]
307    CodeRTNS,
308    #[serde(rename = "MPNS")]
309    CodeMPNS,
310    #[serde(rename = "BOOK")]
311    CodeBOOK,
312}
313
314impl ClearingChannel2Code {
315    pub fn validate(&self) -> Result<(), ValidationError> {
316        Ok(())
317    }
318}
319
320// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
321#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
322pub struct ClearingSystemIdentification2Choice1 {
323    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
324    pub cd: Option<String>,
325}
326
327impl ClearingSystemIdentification2Choice1 {
328    pub fn validate(&self) -> Result<(), ValidationError> {
329        if let Some(ref val) = self.cd {
330            if val.chars().count() < 1 {
331                return Err(ValidationError::new(
332                    1001,
333                    "cd is shorter than the minimum length of 1".to_string(),
334                ));
335            }
336            if val.chars().count() > 5 {
337                return Err(ValidationError::new(
338                    1002,
339                    "cd exceeds the maximum length of 5".to_string(),
340                ));
341            }
342        }
343        Ok(())
344    }
345}
346
347// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
348#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
349pub struct ClearingSystemMemberIdentification21 {
350    #[serde(rename = "ClrSysId")]
351    pub clr_sys_id: ClearingSystemIdentification2Choice1,
352    #[serde(rename = "MmbId")]
353    pub mmb_id: String,
354}
355
356impl ClearingSystemMemberIdentification21 {
357    pub fn validate(&self) -> Result<(), ValidationError> {
358        self.clr_sys_id.validate()?;
359        if self.mmb_id.chars().count() < 1 {
360            return Err(ValidationError::new(
361                1001,
362                "mmb_id is shorter than the minimum length of 1".to_string(),
363            ));
364        }
365        if self.mmb_id.chars().count() > 28 {
366            return Err(ValidationError::new(
367                1002,
368                "mmb_id exceeds the maximum length of 28".to_string(),
369            ));
370        }
371        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
372        if !pattern.is_match(&self.mmb_id) {
373            return Err(ValidationError::new(
374                1005,
375                "mmb_id does not match the required pattern".to_string(),
376            ));
377        }
378        Ok(())
379    }
380}
381
382// CreditTransferTransaction391: 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.
383#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
384pub struct CreditTransferTransaction391 {
385    #[serde(rename = "PmtId")]
386    pub pmt_id: PaymentIdentification71,
387    #[serde(rename = "PmtTpInf", skip_serializing_if = "Option::is_none")]
388    pub pmt_tp_inf: Option<PaymentTypeInformation281>,
389    #[serde(rename = "IntrBkSttlmAmt")]
390    pub intr_bk_sttlm_amt: CBPRAmount1,
391    #[serde(rename = "IntrBkSttlmDt")]
392    pub intr_bk_sttlm_dt: String,
393    #[serde(rename = "SttlmPrty", skip_serializing_if = "Option::is_none")]
394    pub sttlm_prty: Option<Priority3Code>,
395    #[serde(rename = "SttlmTmIndctn", skip_serializing_if = "Option::is_none")]
396    pub sttlm_tm_indctn: Option<SettlementDateTimeIndication11>,
397    #[serde(rename = "SttlmTmReq", skip_serializing_if = "Option::is_none")]
398    pub sttlm_tm_req: Option<SettlementTimeRequest21>,
399    #[serde(rename = "InstdAmt", skip_serializing_if = "Option::is_none")]
400    pub instd_amt: Option<CBPRAmount1>,
401    #[serde(rename = "XchgRate", skip_serializing_if = "Option::is_none")]
402    pub xchg_rate: Option<f64>,
403    #[serde(rename = "ChrgBr")]
404    pub chrg_br: ChargeBearerType1Code1,
405    #[serde(rename = "ChrgsInf", skip_serializing_if = "Option::is_none")]
406    pub chrgs_inf: Option<Vec<Charges71>>,
407    #[serde(rename = "PrvsInstgAgt1", skip_serializing_if = "Option::is_none")]
408    pub prvs_instg_agt1: Option<BranchAndFinancialInstitutionIdentification61>,
409    #[serde(rename = "PrvsInstgAgt1Acct", skip_serializing_if = "Option::is_none")]
410    pub prvs_instg_agt1_acct: Option<CashAccount381>,
411    #[serde(rename = "PrvsInstgAgt2", skip_serializing_if = "Option::is_none")]
412    pub prvs_instg_agt2: Option<BranchAndFinancialInstitutionIdentification61>,
413    #[serde(rename = "PrvsInstgAgt2Acct", skip_serializing_if = "Option::is_none")]
414    pub prvs_instg_agt2_acct: Option<CashAccount381>,
415    #[serde(rename = "PrvsInstgAgt3", skip_serializing_if = "Option::is_none")]
416    pub prvs_instg_agt3: Option<BranchAndFinancialInstitutionIdentification61>,
417    #[serde(rename = "PrvsInstgAgt3Acct", skip_serializing_if = "Option::is_none")]
418    pub prvs_instg_agt3_acct: Option<CashAccount381>,
419    #[serde(rename = "InstgAgt")]
420    pub instg_agt: BranchAndFinancialInstitutionIdentification61,
421    #[serde(rename = "InstdAgt")]
422    pub instd_agt: BranchAndFinancialInstitutionIdentification61,
423    #[serde(rename = "IntrmyAgt1", skip_serializing_if = "Option::is_none")]
424    pub intrmy_agt1: Option<BranchAndFinancialInstitutionIdentification61>,
425    #[serde(rename = "IntrmyAgt1Acct", skip_serializing_if = "Option::is_none")]
426    pub intrmy_agt1_acct: Option<CashAccount381>,
427    #[serde(rename = "IntrmyAgt2", skip_serializing_if = "Option::is_none")]
428    pub intrmy_agt2: Option<BranchAndFinancialInstitutionIdentification61>,
429    #[serde(rename = "IntrmyAgt2Acct", skip_serializing_if = "Option::is_none")]
430    pub intrmy_agt2_acct: Option<CashAccount381>,
431    #[serde(rename = "IntrmyAgt3", skip_serializing_if = "Option::is_none")]
432    pub intrmy_agt3: Option<BranchAndFinancialInstitutionIdentification61>,
433    #[serde(rename = "IntrmyAgt3Acct", skip_serializing_if = "Option::is_none")]
434    pub intrmy_agt3_acct: Option<CashAccount381>,
435    #[serde(rename = "UltmtDbtr", skip_serializing_if = "Option::is_none")]
436    pub ultmt_dbtr: Option<PartyIdentification1351>,
437    #[serde(rename = "InitgPty", skip_serializing_if = "Option::is_none")]
438    pub initg_pty: Option<PartyIdentification1351>,
439    #[serde(rename = "Dbtr")]
440    pub dbtr: PartyIdentification1352,
441    #[serde(rename = "DbtrAcct", skip_serializing_if = "Option::is_none")]
442    pub dbtr_acct: Option<CashAccount381>,
443    #[serde(rename = "DbtrAgt")]
444    pub dbtr_agt: BranchAndFinancialInstitutionIdentification61,
445    #[serde(rename = "DbtrAgtAcct", skip_serializing_if = "Option::is_none")]
446    pub dbtr_agt_acct: Option<CashAccount381>,
447    #[serde(rename = "CdtrAgt")]
448    pub cdtr_agt: BranchAndFinancialInstitutionIdentification61,
449    #[serde(rename = "CdtrAgtAcct", skip_serializing_if = "Option::is_none")]
450    pub cdtr_agt_acct: Option<CashAccount381>,
451    #[serde(rename = "Cdtr")]
452    pub cdtr: PartyIdentification1353,
453    #[serde(rename = "CdtrAcct")]
454    pub cdtr_acct: CashAccount381,
455    #[serde(rename = "UltmtCdtr", skip_serializing_if = "Option::is_none")]
456    pub ultmt_cdtr: Option<PartyIdentification1351>,
457    #[serde(rename = "Purp", skip_serializing_if = "Option::is_none")]
458    pub purp: Option<Purpose2Choice1>,
459    #[serde(rename = "RgltryRptg", skip_serializing_if = "Option::is_none")]
460    pub rgltry_rptg: Option<Vec<RegulatoryReporting31>>,
461    #[serde(rename = "RltdRmtInf", skip_serializing_if = "Option::is_none")]
462    pub rltd_rmt_inf: Option<RemittanceLocation71>,
463    #[serde(rename = "RmtInf", skip_serializing_if = "Option::is_none")]
464    pub rmt_inf: Option<RemittanceInformation161>,
465}
466
467impl CreditTransferTransaction391 {
468    pub fn validate(&self) -> Result<(), ValidationError> {
469        self.pmt_id.validate()?;
470        if let Some(ref val) = self.pmt_tp_inf {
471            val.validate()?
472        }
473        self.intr_bk_sttlm_amt.validate()?;
474        if let Some(ref val) = self.sttlm_prty {
475            val.validate()?
476        }
477        if let Some(ref val) = self.sttlm_tm_indctn {
478            val.validate()?
479        }
480        if let Some(ref val) = self.sttlm_tm_req {
481            val.validate()?
482        }
483        if let Some(ref val) = self.instd_amt {
484            val.validate()?
485        }
486        self.chrg_br.validate()?;
487        if let Some(ref vec) = self.chrgs_inf {
488            for item in vec {
489                item.validate()?
490            }
491        }
492        if let Some(ref val) = self.prvs_instg_agt1 {
493            val.validate()?
494        }
495        if let Some(ref val) = self.prvs_instg_agt1_acct {
496            val.validate()?
497        }
498        if let Some(ref val) = self.prvs_instg_agt2 {
499            val.validate()?
500        }
501        if let Some(ref val) = self.prvs_instg_agt2_acct {
502            val.validate()?
503        }
504        if let Some(ref val) = self.prvs_instg_agt3 {
505            val.validate()?
506        }
507        if let Some(ref val) = self.prvs_instg_agt3_acct {
508            val.validate()?
509        }
510        self.instg_agt.validate()?;
511        self.instd_agt.validate()?;
512        if let Some(ref val) = self.intrmy_agt1 {
513            val.validate()?
514        }
515        if let Some(ref val) = self.intrmy_agt1_acct {
516            val.validate()?
517        }
518        if let Some(ref val) = self.intrmy_agt2 {
519            val.validate()?
520        }
521        if let Some(ref val) = self.intrmy_agt2_acct {
522            val.validate()?
523        }
524        if let Some(ref val) = self.intrmy_agt3 {
525            val.validate()?
526        }
527        if let Some(ref val) = self.intrmy_agt3_acct {
528            val.validate()?
529        }
530        if let Some(ref val) = self.ultmt_dbtr {
531            val.validate()?
532        }
533        if let Some(ref val) = self.initg_pty {
534            val.validate()?
535        }
536        self.dbtr.validate()?;
537        if let Some(ref val) = self.dbtr_acct {
538            val.validate()?
539        }
540        self.dbtr_agt.validate()?;
541        if let Some(ref val) = self.dbtr_agt_acct {
542            val.validate()?
543        }
544        self.cdtr_agt.validate()?;
545        if let Some(ref val) = self.cdtr_agt_acct {
546            val.validate()?
547        }
548        self.cdtr.validate()?;
549        self.cdtr_acct.validate()?;
550        if let Some(ref val) = self.ultmt_cdtr {
551            val.validate()?
552        }
553        if let Some(ref val) = self.purp {
554            val.validate()?
555        }
556        if let Some(ref vec) = self.rgltry_rptg {
557            for item in vec {
558                item.validate()?
559            }
560        }
561        if let Some(ref val) = self.rltd_rmt_inf {
562            val.validate()?
563        }
564        if let Some(ref val) = self.rmt_inf {
565            val.validate()?
566        }
567        Ok(())
568    }
569}
570
571// DateAndPlaceOfBirth11: Country where a person was born.
572#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
573pub struct DateAndPlaceOfBirth11 {
574    #[serde(rename = "BirthDt")]
575    pub birth_dt: String,
576    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
577    pub prvc_of_birth: Option<String>,
578    #[serde(rename = "CityOfBirth")]
579    pub city_of_birth: String,
580    #[serde(rename = "CtryOfBirth")]
581    pub ctry_of_birth: String,
582}
583
584impl DateAndPlaceOfBirth11 {
585    pub fn validate(&self) -> Result<(), ValidationError> {
586        if let Some(ref val) = self.prvc_of_birth {
587            if val.chars().count() < 1 {
588                return Err(ValidationError::new(
589                    1001,
590                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
591                ));
592            }
593            if val.chars().count() > 35 {
594                return Err(ValidationError::new(
595                    1002,
596                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
597                ));
598            }
599            let pattern = Regex::new(
600                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
601            )
602            .unwrap();
603            if !pattern.is_match(val) {
604                return Err(ValidationError::new(
605                    1005,
606                    "prvc_of_birth does not match the required pattern".to_string(),
607                ));
608            }
609        }
610        if self.city_of_birth.chars().count() < 1 {
611            return Err(ValidationError::new(
612                1001,
613                "city_of_birth is shorter than the minimum length of 1".to_string(),
614            ));
615        }
616        if self.city_of_birth.chars().count() > 35 {
617            return Err(ValidationError::new(
618                1002,
619                "city_of_birth exceeds the maximum length of 35".to_string(),
620            ));
621        }
622        let pattern =
623            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
624                .unwrap();
625        if !pattern.is_match(&self.city_of_birth) {
626            return Err(ValidationError::new(
627                1005,
628                "city_of_birth does not match the required pattern".to_string(),
629            ));
630        }
631        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
632        if !pattern.is_match(&self.ctry_of_birth) {
633            return Err(ValidationError::new(
634                1005,
635                "ctry_of_birth does not match the required pattern".to_string(),
636            ));
637        }
638        Ok(())
639    }
640}
641
642// FIToFICustomerCreditTransferV08: Set of elements providing information specific to the individual credit transfer(s).
643#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
644pub struct FIToFICustomerCreditTransferV08 {
645    #[serde(rename = "GrpHdr")]
646    pub grp_hdr: GroupHeader931,
647    #[serde(rename = "CdtTrfTxInf")]
648    pub cdt_trf_tx_inf: CreditTransferTransaction391,
649}
650
651impl FIToFICustomerCreditTransferV08 {
652    pub fn validate(&self) -> Result<(), ValidationError> {
653        self.grp_hdr.validate()?;
654        self.cdt_trf_tx_inf.validate()?;
655        Ok(())
656    }
657}
658
659// FinancialInstitutionIdentification181: Legal entity identifier of the financial institution.
660#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
661pub struct FinancialInstitutionIdentification181 {
662    #[serde(rename = "BICFI")]
663    pub bicfi: String,
664    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
665    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
666    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
667    pub lei: Option<String>,
668}
669
670impl FinancialInstitutionIdentification181 {
671    pub fn validate(&self) -> Result<(), ValidationError> {
672        let pattern =
673            Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
674        if !pattern.is_match(&self.bicfi) {
675            return Err(ValidationError::new(
676                1005,
677                "bicfi does not match the required pattern".to_string(),
678            ));
679        }
680        if let Some(ref val) = self.clr_sys_mmb_id {
681            val.validate()?
682        }
683        if let Some(ref val) = self.lei {
684            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
685            if !pattern.is_match(val) {
686                return Err(ValidationError::new(
687                    1005,
688                    "lei does not match the required pattern".to_string(),
689                ));
690            }
691        }
692        Ok(())
693    }
694}
695
696// GenericAccountIdentification11: Entity that assigns the identification.
697#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
698pub struct GenericAccountIdentification11 {
699    #[serde(rename = "Id")]
700    pub id: String,
701    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
702    pub schme_nm: Option<AccountSchemeName1Choice1>,
703    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
704    pub issr: Option<String>,
705}
706
707impl GenericAccountIdentification11 {
708    pub fn validate(&self) -> Result<(), ValidationError> {
709        if self.id.chars().count() < 1 {
710            return Err(ValidationError::new(
711                1001,
712                "id is shorter than the minimum length of 1".to_string(),
713            ));
714        }
715        if self.id.chars().count() > 34 {
716            return Err(ValidationError::new(
717                1002,
718                "id exceeds the maximum length of 34".to_string(),
719            ));
720        }
721        let pattern = Regex::new("([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]*(/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ])?)*)").unwrap();
722        if !pattern.is_match(&self.id) {
723            return Err(ValidationError::new(
724                1005,
725                "id does not match the required pattern".to_string(),
726            ));
727        }
728        if let Some(ref val) = self.schme_nm {
729            val.validate()?
730        }
731        if let Some(ref val) = self.issr {
732            if val.chars().count() < 1 {
733                return Err(ValidationError::new(
734                    1001,
735                    "issr is shorter than the minimum length of 1".to_string(),
736                ));
737            }
738            if val.chars().count() > 35 {
739                return Err(ValidationError::new(
740                    1002,
741                    "issr exceeds the maximum length of 35".to_string(),
742                ));
743            }
744            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
745            if !pattern.is_match(val) {
746                return Err(ValidationError::new(
747                    1005,
748                    "issr does not match the required pattern".to_string(),
749                ));
750            }
751        }
752        Ok(())
753    }
754}
755
756// GenericOrganisationIdentification11: Entity that assigns the identification.
757#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
758pub struct GenericOrganisationIdentification11 {
759    #[serde(rename = "Id")]
760    pub id: String,
761    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
762    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice1>,
763    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
764    pub issr: Option<String>,
765}
766
767impl GenericOrganisationIdentification11 {
768    pub fn validate(&self) -> Result<(), ValidationError> {
769        if self.id.chars().count() < 1 {
770            return Err(ValidationError::new(
771                1001,
772                "id is shorter than the minimum length of 1".to_string(),
773            ));
774        }
775        if self.id.chars().count() > 35 {
776            return Err(ValidationError::new(
777                1002,
778                "id exceeds the maximum length of 35".to_string(),
779            ));
780        }
781        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
782        if !pattern.is_match(&self.id) {
783            return Err(ValidationError::new(
784                1005,
785                "id does not match the required pattern".to_string(),
786            ));
787        }
788        if let Some(ref val) = self.schme_nm {
789            val.validate()?
790        }
791        if let Some(ref val) = self.issr {
792            if val.chars().count() < 1 {
793                return Err(ValidationError::new(
794                    1001,
795                    "issr is shorter than the minimum length of 1".to_string(),
796                ));
797            }
798            if val.chars().count() > 35 {
799                return Err(ValidationError::new(
800                    1002,
801                    "issr exceeds the maximum length of 35".to_string(),
802                ));
803            }
804            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
805            if !pattern.is_match(val) {
806                return Err(ValidationError::new(
807                    1005,
808                    "issr does not match the required pattern".to_string(),
809                ));
810            }
811        }
812        Ok(())
813    }
814}
815
816// GenericOrganisationIdentification12: Entity that assigns the identification.
817#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
818pub struct GenericOrganisationIdentification12 {
819    #[serde(rename = "Id")]
820    pub id: String,
821    #[serde(rename = "SchmeNm")]
822    pub schme_nm: OrganisationIdentificationSchemeName1Choice2,
823    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
824    pub issr: Option<String>,
825}
826
827impl GenericOrganisationIdentification12 {
828    pub fn validate(&self) -> Result<(), ValidationError> {
829        if self.id.chars().count() < 1 {
830            return Err(ValidationError::new(
831                1001,
832                "id is shorter than the minimum length of 1".to_string(),
833            ));
834        }
835        if self.id.chars().count() > 35 {
836            return Err(ValidationError::new(
837                1002,
838                "id exceeds the maximum length of 35".to_string(),
839            ));
840        }
841        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
842        if !pattern.is_match(&self.id) {
843            return Err(ValidationError::new(
844                1005,
845                "id does not match the required pattern".to_string(),
846            ));
847        }
848        self.schme_nm.validate()?;
849        if let Some(ref val) = self.issr {
850            if val.chars().count() < 1 {
851                return Err(ValidationError::new(
852                    1001,
853                    "issr is shorter than the minimum length of 1".to_string(),
854                ));
855            }
856            if val.chars().count() > 35 {
857                return Err(ValidationError::new(
858                    1002,
859                    "issr exceeds the maximum length of 35".to_string(),
860                ));
861            }
862            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
863            if !pattern.is_match(val) {
864                return Err(ValidationError::new(
865                    1005,
866                    "issr does not match the required pattern".to_string(),
867                ));
868            }
869        }
870        Ok(())
871    }
872}
873
874// GenericPersonIdentification11: Entity that assigns the identification.
875#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
876pub struct GenericPersonIdentification11 {
877    #[serde(rename = "Id")]
878    pub id: String,
879    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
880    pub schme_nm: Option<PersonIdentificationSchemeName1Choice1>,
881    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
882    pub issr: Option<String>,
883}
884
885impl GenericPersonIdentification11 {
886    pub fn validate(&self) -> Result<(), ValidationError> {
887        if self.id.chars().count() < 1 {
888            return Err(ValidationError::new(
889                1001,
890                "id is shorter than the minimum length of 1".to_string(),
891            ));
892        }
893        if self.id.chars().count() > 35 {
894            return Err(ValidationError::new(
895                1002,
896                "id exceeds the maximum length of 35".to_string(),
897            ));
898        }
899        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
900        if !pattern.is_match(&self.id) {
901            return Err(ValidationError::new(
902                1005,
903                "id does not match the required pattern".to_string(),
904            ));
905        }
906        if let Some(ref val) = self.schme_nm {
907            val.validate()?
908        }
909        if let Some(ref val) = self.issr {
910            if val.chars().count() < 1 {
911                return Err(ValidationError::new(
912                    1001,
913                    "issr is shorter than the minimum length of 1".to_string(),
914                ));
915            }
916            if val.chars().count() > 35 {
917                return Err(ValidationError::new(
918                    1002,
919                    "issr exceeds the maximum length of 35".to_string(),
920                ));
921            }
922            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
923            if !pattern.is_match(val) {
924                return Err(ValidationError::new(
925                    1005,
926                    "issr does not match the required pattern".to_string(),
927                ));
928            }
929        }
930        Ok(())
931    }
932}
933
934// GenericPersonIdentification12: Entity that assigns the identification.
935#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
936pub struct GenericPersonIdentification12 {
937    #[serde(rename = "Id")]
938    pub id: String,
939    #[serde(rename = "SchmeNm")]
940    pub schme_nm: PersonIdentificationSchemeName1Choice2,
941    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
942    pub issr: Option<String>,
943}
944
945impl GenericPersonIdentification12 {
946    pub fn validate(&self) -> Result<(), ValidationError> {
947        if self.id.chars().count() < 1 {
948            return Err(ValidationError::new(
949                1001,
950                "id is shorter than the minimum length of 1".to_string(),
951            ));
952        }
953        if self.id.chars().count() > 35 {
954            return Err(ValidationError::new(
955                1002,
956                "id exceeds the maximum length of 35".to_string(),
957            ));
958        }
959        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
960        if !pattern.is_match(&self.id) {
961            return Err(ValidationError::new(
962                1005,
963                "id does not match the required pattern".to_string(),
964            ));
965        }
966        self.schme_nm.validate()?;
967        if let Some(ref val) = self.issr {
968            if val.chars().count() < 1 {
969                return Err(ValidationError::new(
970                    1001,
971                    "issr is shorter than the minimum length of 1".to_string(),
972                ));
973            }
974            if val.chars().count() > 35 {
975                return Err(ValidationError::new(
976                    1002,
977                    "issr exceeds the maximum length of 35".to_string(),
978                ));
979            }
980            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
981            if !pattern.is_match(val) {
982                return Err(ValidationError::new(
983                    1005,
984                    "issr does not match the required pattern".to_string(),
985                ));
986            }
987        }
988        Ok(())
989    }
990}
991
992// GroupHeader931: Specifies the details on how the settlement of the transaction(s) between the instructing agent and the instructed agent is completed.
993#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
994pub struct GroupHeader931 {
995    #[serde(rename = "MsgId")]
996    pub msg_id: String,
997    #[serde(rename = "CreDtTm")]
998    pub cre_dt_tm: String,
999    #[serde(rename = "NbOfTxs")]
1000    pub nb_of_txs: Max15NumericTextfixed,
1001    #[serde(rename = "SttlmInf")]
1002    pub sttlm_inf: SettlementInstruction71,
1003}
1004
1005impl GroupHeader931 {
1006    pub fn validate(&self) -> Result<(), ValidationError> {
1007        if self.msg_id.chars().count() < 1 {
1008            return Err(ValidationError::new(
1009                1001,
1010                "msg_id is shorter than the minimum length of 1".to_string(),
1011            ));
1012        }
1013        if self.msg_id.chars().count() > 35 {
1014            return Err(ValidationError::new(
1015                1002,
1016                "msg_id exceeds the maximum length of 35".to_string(),
1017            ));
1018        }
1019        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1020        if !pattern.is_match(&self.msg_id) {
1021            return Err(ValidationError::new(
1022                1005,
1023                "msg_id does not match the required pattern".to_string(),
1024            ));
1025        }
1026        let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
1027        if !pattern.is_match(&self.cre_dt_tm) {
1028            return Err(ValidationError::new(
1029                1005,
1030                "cre_dt_tm does not match the required pattern".to_string(),
1031            ));
1032        }
1033        self.nb_of_txs.validate()?;
1034        self.sttlm_inf.validate()?;
1035        Ok(())
1036    }
1037}
1038
1039// LocalInstrument2Choice1: Specifies the local instrument, as published in an external local instrument code list.
1040#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1041pub struct LocalInstrument2Choice1 {
1042    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1043    pub cd: Option<String>,
1044}
1045
1046impl LocalInstrument2Choice1 {
1047    pub fn validate(&self) -> Result<(), ValidationError> {
1048        if let Some(ref val) = self.cd {
1049            if val.chars().count() < 1 {
1050                return Err(ValidationError::new(
1051                    1001,
1052                    "cd is shorter than the minimum length of 1".to_string(),
1053                ));
1054            }
1055            if val.chars().count() > 35 {
1056                return Err(ValidationError::new(
1057                    1002,
1058                    "cd exceeds the maximum length of 35".to_string(),
1059                ));
1060            }
1061        }
1062        Ok(())
1063    }
1064}
1065
1066// Max15NumericText_fixed: 1
1067#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1068pub enum Max15NumericTextfixed {
1069    #[default]
1070    #[serde(rename = "1")]
1071    Code1,
1072}
1073
1074impl Max15NumericTextfixed {
1075    pub fn validate(&self) -> Result<(), ValidationError> {
1076        Ok(())
1077    }
1078}
1079
1080// NameAndAddress161: Postal address of a party.
1081#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1082pub struct NameAndAddress161 {
1083    #[serde(rename = "Nm")]
1084    pub nm: String,
1085    #[serde(rename = "Adr")]
1086    pub adr: PostalAddress242,
1087}
1088
1089impl NameAndAddress161 {
1090    pub fn validate(&self) -> Result<(), ValidationError> {
1091        if self.nm.chars().count() < 1 {
1092            return Err(ValidationError::new(
1093                1001,
1094                "nm is shorter than the minimum length of 1".to_string(),
1095            ));
1096        }
1097        if self.nm.chars().count() > 140 {
1098            return Err(ValidationError::new(
1099                1002,
1100                "nm exceeds the maximum length of 140".to_string(),
1101            ));
1102        }
1103        let pattern =
1104            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
1105                .unwrap();
1106        if !pattern.is_match(&self.nm) {
1107            return Err(ValidationError::new(
1108                1005,
1109                "nm does not match the required pattern".to_string(),
1110            ));
1111        }
1112        self.adr.validate()?;
1113        Ok(())
1114    }
1115}
1116
1117// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
1118#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1119pub struct OrganisationIdentification291 {
1120    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
1121    pub any_bic: Option<String>,
1122    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1123    pub lei: Option<String>,
1124    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1125    pub othr: Option<Vec<GenericOrganisationIdentification11>>,
1126}
1127
1128impl OrganisationIdentification291 {
1129    pub fn validate(&self) -> Result<(), ValidationError> {
1130        if let Some(ref val) = self.any_bic {
1131            let pattern =
1132                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1133            if !pattern.is_match(val) {
1134                return Err(ValidationError::new(
1135                    1005,
1136                    "any_bic does not match the required pattern".to_string(),
1137                ));
1138            }
1139        }
1140        if let Some(ref val) = self.lei {
1141            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1142            if !pattern.is_match(val) {
1143                return Err(ValidationError::new(
1144                    1005,
1145                    "lei does not match the required pattern".to_string(),
1146                ));
1147            }
1148        }
1149        if let Some(ref vec) = self.othr {
1150            for item in vec {
1151                item.validate()?
1152            }
1153        }
1154        Ok(())
1155    }
1156}
1157
1158// OrganisationIdentification292: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
1159#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1160pub struct OrganisationIdentification292 {
1161    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
1162    pub any_bic: Option<String>,
1163    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
1164    pub lei: Option<String>,
1165    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1166    pub othr: Option<Vec<GenericOrganisationIdentification12>>,
1167}
1168
1169impl OrganisationIdentification292 {
1170    pub fn validate(&self) -> Result<(), ValidationError> {
1171        if let Some(ref val) = self.any_bic {
1172            let pattern =
1173                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
1174            if !pattern.is_match(val) {
1175                return Err(ValidationError::new(
1176                    1005,
1177                    "any_bic does not match the required pattern".to_string(),
1178                ));
1179            }
1180        }
1181        if let Some(ref val) = self.lei {
1182            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
1183            if !pattern.is_match(val) {
1184                return Err(ValidationError::new(
1185                    1005,
1186                    "lei does not match the required pattern".to_string(),
1187                ));
1188            }
1189        }
1190        if let Some(ref vec) = self.othr {
1191            for item in vec {
1192                item.validate()?
1193            }
1194        }
1195        Ok(())
1196    }
1197}
1198
1199// OrganisationIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
1200#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1201pub struct OrganisationIdentificationSchemeName1Choice1 {
1202    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1203    pub cd: Option<String>,
1204    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1205    pub prtry: Option<String>,
1206}
1207
1208impl OrganisationIdentificationSchemeName1Choice1 {
1209    pub fn validate(&self) -> Result<(), ValidationError> {
1210        if let Some(ref val) = self.cd {
1211            if val.chars().count() < 1 {
1212                return Err(ValidationError::new(
1213                    1001,
1214                    "cd is shorter than the minimum length of 1".to_string(),
1215                ));
1216            }
1217            if val.chars().count() > 4 {
1218                return Err(ValidationError::new(
1219                    1002,
1220                    "cd exceeds the maximum length of 4".to_string(),
1221                ));
1222            }
1223        }
1224        if let Some(ref val) = self.prtry {
1225            if val.chars().count() < 1 {
1226                return Err(ValidationError::new(
1227                    1001,
1228                    "prtry is shorter than the minimum length of 1".to_string(),
1229                ));
1230            }
1231            if val.chars().count() > 35 {
1232                return Err(ValidationError::new(
1233                    1002,
1234                    "prtry exceeds the maximum length of 35".to_string(),
1235                ));
1236            }
1237            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1238            if !pattern.is_match(val) {
1239                return Err(ValidationError::new(
1240                    1005,
1241                    "prtry does not match the required pattern".to_string(),
1242                ));
1243            }
1244        }
1245        Ok(())
1246    }
1247}
1248
1249// OrganisationIdentificationSchemeName1Choice2: Name of the identification scheme, in a coded form as published in an external list.
1250#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1251pub struct OrganisationIdentificationSchemeName1Choice2 {
1252    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1253    pub cd: Option<String>,
1254}
1255
1256impl OrganisationIdentificationSchemeName1Choice2 {
1257    pub fn validate(&self) -> Result<(), ValidationError> {
1258        if let Some(ref val) = self.cd {
1259            if val.chars().count() < 1 {
1260                return Err(ValidationError::new(
1261                    1001,
1262                    "cd is shorter than the minimum length of 1".to_string(),
1263                ));
1264            }
1265            if val.chars().count() > 4 {
1266                return Err(ValidationError::new(
1267                    1002,
1268                    "cd exceeds the maximum length of 4".to_string(),
1269                ));
1270            }
1271        }
1272        Ok(())
1273    }
1274}
1275
1276// Party38Choice1: Unique and unambiguous identification of a person, for example a passport.
1277#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1278pub struct Party38Choice1 {
1279    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1280    pub org_id: Option<OrganisationIdentification291>,
1281    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1282    pub prvt_id: Option<PersonIdentification131>,
1283}
1284
1285impl Party38Choice1 {
1286    pub fn validate(&self) -> Result<(), ValidationError> {
1287        if let Some(ref val) = self.org_id {
1288            val.validate()?
1289        }
1290        if let Some(ref val) = self.prvt_id {
1291            val.validate()?
1292        }
1293        Ok(())
1294    }
1295}
1296
1297// Party38Choice2: Unique and unambiguous identification of a person, for example a passport.
1298#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1299pub struct Party38Choice2 {
1300    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
1301    pub org_id: Option<OrganisationIdentification292>,
1302    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
1303    pub prvt_id: Option<PersonIdentification132>,
1304}
1305
1306impl Party38Choice2 {
1307    pub fn validate(&self) -> Result<(), ValidationError> {
1308        if let Some(ref val) = self.org_id {
1309            val.validate()?
1310        }
1311        if let Some(ref val) = self.prvt_id {
1312            val.validate()?
1313        }
1314        Ok(())
1315    }
1316}
1317
1318// PartyIdentification1351: Country in which a person resides (the place of a person's home). In the case of a company, it is the country from which the affairs of that company are directed.
1319#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1320pub struct PartyIdentification1351 {
1321    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1322    pub nm: Option<String>,
1323    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1324    pub pstl_adr: Option<PostalAddress241>,
1325    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1326    pub id: Option<Party38Choice1>,
1327    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1328    pub ctry_of_res: Option<String>,
1329}
1330
1331impl PartyIdentification1351 {
1332    pub fn validate(&self) -> Result<(), ValidationError> {
1333        if let Some(ref val) = self.nm {
1334            if val.chars().count() < 1 {
1335                return Err(ValidationError::new(
1336                    1001,
1337                    "nm is shorter than the minimum length of 1".to_string(),
1338                ));
1339            }
1340            if val.chars().count() > 140 {
1341                return Err(ValidationError::new(
1342                    1002,
1343                    "nm exceeds the maximum length of 140".to_string(),
1344                ));
1345            }
1346            let pattern = Regex::new(
1347                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1348            )
1349            .unwrap();
1350            if !pattern.is_match(val) {
1351                return Err(ValidationError::new(
1352                    1005,
1353                    "nm does not match the required pattern".to_string(),
1354                ));
1355            }
1356        }
1357        if let Some(ref val) = self.pstl_adr {
1358            val.validate()?
1359        }
1360        if let Some(ref val) = self.id {
1361            val.validate()?
1362        }
1363        if let Some(ref val) = self.ctry_of_res {
1364            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1365            if !pattern.is_match(val) {
1366                return Err(ValidationError::new(
1367                    1005,
1368                    "ctry_of_res does not match the required pattern".to_string(),
1369                ));
1370            }
1371        }
1372        Ok(())
1373    }
1374}
1375
1376// 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.
1377#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1378pub struct PartyIdentification1352 {
1379    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1380    pub nm: Option<String>,
1381    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1382    pub pstl_adr: Option<PostalAddress242>,
1383    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1384    pub id: Option<Party38Choice2>,
1385    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1386    pub ctry_of_res: Option<String>,
1387}
1388
1389impl PartyIdentification1352 {
1390    pub fn validate(&self) -> Result<(), ValidationError> {
1391        if let Some(ref val) = self.nm {
1392            if val.chars().count() < 1 {
1393                return Err(ValidationError::new(
1394                    1001,
1395                    "nm is shorter than the minimum length of 1".to_string(),
1396                ));
1397            }
1398            if val.chars().count() > 140 {
1399                return Err(ValidationError::new(
1400                    1002,
1401                    "nm exceeds the maximum length of 140".to_string(),
1402                ));
1403            }
1404            let pattern = Regex::new(
1405                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1406            )
1407            .unwrap();
1408            if !pattern.is_match(val) {
1409                return Err(ValidationError::new(
1410                    1005,
1411                    "nm does not match the required pattern".to_string(),
1412                ));
1413            }
1414        }
1415        if let Some(ref val) = self.pstl_adr {
1416            val.validate()?
1417        }
1418        if let Some(ref val) = self.id {
1419            val.validate()?
1420        }
1421        if let Some(ref val) = self.ctry_of_res {
1422            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1423            if !pattern.is_match(val) {
1424                return Err(ValidationError::new(
1425                    1005,
1426                    "ctry_of_res does not match the required pattern".to_string(),
1427                ));
1428            }
1429        }
1430        Ok(())
1431    }
1432}
1433
1434// 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.
1435#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1436pub struct PartyIdentification1353 {
1437    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
1438    pub nm: Option<String>,
1439    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
1440    pub pstl_adr: Option<PostalAddress242>,
1441    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
1442    pub id: Option<Party38Choice1>,
1443    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
1444    pub ctry_of_res: Option<String>,
1445}
1446
1447impl PartyIdentification1353 {
1448    pub fn validate(&self) -> Result<(), ValidationError> {
1449        if let Some(ref val) = self.nm {
1450            if val.chars().count() < 1 {
1451                return Err(ValidationError::new(
1452                    1001,
1453                    "nm is shorter than the minimum length of 1".to_string(),
1454                ));
1455            }
1456            if val.chars().count() > 140 {
1457                return Err(ValidationError::new(
1458                    1002,
1459                    "nm exceeds the maximum length of 140".to_string(),
1460                ));
1461            }
1462            let pattern = Regex::new(
1463                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1464            )
1465            .unwrap();
1466            if !pattern.is_match(val) {
1467                return Err(ValidationError::new(
1468                    1005,
1469                    "nm does not match the required pattern".to_string(),
1470                ));
1471            }
1472        }
1473        if let Some(ref val) = self.pstl_adr {
1474            val.validate()?
1475        }
1476        if let Some(ref val) = self.id {
1477            val.validate()?
1478        }
1479        if let Some(ref val) = self.ctry_of_res {
1480            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1481            if !pattern.is_match(val) {
1482                return Err(ValidationError::new(
1483                    1005,
1484                    "ctry_of_res does not match the required pattern".to_string(),
1485                ));
1486            }
1487        }
1488        Ok(())
1489    }
1490}
1491
1492// PaymentIdentification71: Unique reference, as assigned by a clearing system, to unambiguously identify the instruction.
1493#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1494pub struct PaymentIdentification71 {
1495    #[serde(rename = "InstrId")]
1496    pub instr_id: String,
1497    #[serde(rename = "EndToEndId")]
1498    pub end_to_end_id: String,
1499    #[serde(rename = "TxId", skip_serializing_if = "Option::is_none")]
1500    pub tx_id: Option<String>,
1501    #[serde(rename = "UETR")]
1502    pub uetr: String,
1503    #[serde(rename = "ClrSysRef", skip_serializing_if = "Option::is_none")]
1504    pub clr_sys_ref: Option<String>,
1505}
1506
1507impl PaymentIdentification71 {
1508    pub fn validate(&self) -> Result<(), ValidationError> {
1509        if self.instr_id.chars().count() < 1 {
1510            return Err(ValidationError::new(
1511                1001,
1512                "instr_id is shorter than the minimum length of 1".to_string(),
1513            ));
1514        }
1515        if self.instr_id.chars().count() > 16 {
1516            return Err(ValidationError::new(
1517                1002,
1518                "instr_id exceeds the maximum length of 16".to_string(),
1519            ));
1520        }
1521        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1522        if !pattern.is_match(&self.instr_id) {
1523            return Err(ValidationError::new(
1524                1005,
1525                "instr_id does not match the required pattern".to_string(),
1526            ));
1527        }
1528        if self.end_to_end_id.chars().count() < 1 {
1529            return Err(ValidationError::new(
1530                1001,
1531                "end_to_end_id is shorter than the minimum length of 1".to_string(),
1532            ));
1533        }
1534        if self.end_to_end_id.chars().count() > 35 {
1535            return Err(ValidationError::new(
1536                1002,
1537                "end_to_end_id exceeds the maximum length of 35".to_string(),
1538            ));
1539        }
1540        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1541        if !pattern.is_match(&self.end_to_end_id) {
1542            return Err(ValidationError::new(
1543                1005,
1544                "end_to_end_id does not match the required pattern".to_string(),
1545            ));
1546        }
1547        if let Some(ref val) = self.tx_id {
1548            if val.chars().count() < 1 {
1549                return Err(ValidationError::new(
1550                    1001,
1551                    "tx_id is shorter than the minimum length of 1".to_string(),
1552                ));
1553            }
1554            if val.chars().count() > 35 {
1555                return Err(ValidationError::new(
1556                    1002,
1557                    "tx_id exceeds the maximum length of 35".to_string(),
1558                ));
1559            }
1560            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1561            if !pattern.is_match(val) {
1562                return Err(ValidationError::new(
1563                    1005,
1564                    "tx_id does not match the required pattern".to_string(),
1565                ));
1566            }
1567        }
1568        let pattern =
1569            Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
1570                .unwrap();
1571        if !pattern.is_match(&self.uetr) {
1572            return Err(ValidationError::new(
1573                1005,
1574                "uetr does not match the required pattern".to_string(),
1575            ));
1576        }
1577        if let Some(ref val) = self.clr_sys_ref {
1578            if val.chars().count() < 1 {
1579                return Err(ValidationError::new(
1580                    1001,
1581                    "clr_sys_ref is shorter than the minimum length of 1".to_string(),
1582                ));
1583            }
1584            if val.chars().count() > 35 {
1585                return Err(ValidationError::new(
1586                    1002,
1587                    "clr_sys_ref exceeds the maximum length of 35".to_string(),
1588                ));
1589            }
1590            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1591            if !pattern.is_match(val) {
1592                return Err(ValidationError::new(
1593                    1005,
1594                    "clr_sys_ref does not match the required pattern".to_string(),
1595                ));
1596            }
1597        }
1598        Ok(())
1599    }
1600}
1601
1602// PaymentTypeInformation281: Specifies the high level purpose of the instruction based on a set of pre-defined categories.
1603// 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.
1604#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1605pub struct PaymentTypeInformation281 {
1606    #[serde(rename = "InstrPrty", skip_serializing_if = "Option::is_none")]
1607    pub instr_prty: Option<Priority2Code>,
1608    #[serde(rename = "ClrChanl", skip_serializing_if = "Option::is_none")]
1609    pub clr_chanl: Option<ClearingChannel2Code>,
1610    #[serde(rename = "SvcLvl", skip_serializing_if = "Option::is_none")]
1611    pub svc_lvl: Option<Vec<ServiceLevel8Choice1>>,
1612    #[serde(rename = "LclInstrm", skip_serializing_if = "Option::is_none")]
1613    pub lcl_instrm: Option<LocalInstrument2Choice1>,
1614    #[serde(rename = "CtgyPurp", skip_serializing_if = "Option::is_none")]
1615    pub ctgy_purp: Option<CategoryPurpose1Choice1>,
1616}
1617
1618impl PaymentTypeInformation281 {
1619    pub fn validate(&self) -> Result<(), ValidationError> {
1620        if let Some(ref val) = self.instr_prty {
1621            val.validate()?
1622        }
1623        if let Some(ref val) = self.clr_chanl {
1624            val.validate()?
1625        }
1626        if let Some(ref vec) = self.svc_lvl {
1627            for item in vec {
1628                item.validate()?
1629            }
1630        }
1631        if let Some(ref val) = self.lcl_instrm {
1632            val.validate()?
1633        }
1634        if let Some(ref val) = self.ctgy_purp {
1635            val.validate()?
1636        }
1637        Ok(())
1638    }
1639}
1640
1641// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
1642#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1643pub struct PersonIdentification131 {
1644    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1645    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
1646    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1647    pub othr: Option<Vec<GenericPersonIdentification11>>,
1648}
1649
1650impl PersonIdentification131 {
1651    pub fn validate(&self) -> Result<(), ValidationError> {
1652        if let Some(ref val) = self.dt_and_plc_of_birth {
1653            val.validate()?
1654        }
1655        if let Some(ref vec) = self.othr {
1656            for item in vec {
1657                item.validate()?
1658            }
1659        }
1660        Ok(())
1661    }
1662}
1663
1664// PersonIdentification132: Unique identification of a person, as assigned by an institution, using an identification scheme.
1665#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1666pub struct PersonIdentification132 {
1667    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
1668    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth11>,
1669    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
1670    pub othr: Option<Vec<GenericPersonIdentification12>>,
1671}
1672
1673impl PersonIdentification132 {
1674    pub fn validate(&self) -> Result<(), ValidationError> {
1675        if let Some(ref val) = self.dt_and_plc_of_birth {
1676            val.validate()?
1677        }
1678        if let Some(ref vec) = self.othr {
1679            for item in vec {
1680                item.validate()?
1681            }
1682        }
1683        Ok(())
1684    }
1685}
1686
1687// PersonIdentificationSchemeName1Choice1: Name of the identification scheme, in a free text form.
1688#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1689pub struct PersonIdentificationSchemeName1Choice1 {
1690    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1691    pub cd: Option<String>,
1692    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1693    pub prtry: Option<String>,
1694}
1695
1696impl PersonIdentificationSchemeName1Choice1 {
1697    pub fn validate(&self) -> Result<(), ValidationError> {
1698        if let Some(ref val) = self.cd {
1699            if val.chars().count() < 1 {
1700                return Err(ValidationError::new(
1701                    1001,
1702                    "cd is shorter than the minimum length of 1".to_string(),
1703                ));
1704            }
1705            if val.chars().count() > 4 {
1706                return Err(ValidationError::new(
1707                    1002,
1708                    "cd exceeds the maximum length of 4".to_string(),
1709                ));
1710            }
1711        }
1712        if let Some(ref val) = self.prtry {
1713            if val.chars().count() < 1 {
1714                return Err(ValidationError::new(
1715                    1001,
1716                    "prtry is shorter than the minimum length of 1".to_string(),
1717                ));
1718            }
1719            if val.chars().count() > 35 {
1720                return Err(ValidationError::new(
1721                    1002,
1722                    "prtry exceeds the maximum length of 35".to_string(),
1723                ));
1724            }
1725            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1726            if !pattern.is_match(val) {
1727                return Err(ValidationError::new(
1728                    1005,
1729                    "prtry does not match the required pattern".to_string(),
1730                ));
1731            }
1732        }
1733        Ok(())
1734    }
1735}
1736
1737// PersonIdentificationSchemeName1Choice2: Name of the identification scheme, in a coded form as published in an external list.
1738#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1739pub struct PersonIdentificationSchemeName1Choice2 {
1740    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1741    pub cd: Option<String>,
1742}
1743
1744impl PersonIdentificationSchemeName1Choice2 {
1745    pub fn validate(&self) -> Result<(), ValidationError> {
1746        if let Some(ref val) = self.cd {
1747            if val.chars().count() < 1 {
1748                return Err(ValidationError::new(
1749                    1001,
1750                    "cd is shorter than the minimum length of 1".to_string(),
1751                ));
1752            }
1753            if val.chars().count() > 4 {
1754                return Err(ValidationError::new(
1755                    1002,
1756                    "cd exceeds the maximum length of 4".to_string(),
1757                ));
1758            }
1759        }
1760        Ok(())
1761    }
1762}
1763
1764// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
1765#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1766pub struct PostalAddress241 {
1767    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
1768    pub dept: Option<String>,
1769    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
1770    pub sub_dept: Option<String>,
1771    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
1772    pub strt_nm: Option<String>,
1773    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
1774    pub bldg_nb: Option<String>,
1775    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
1776    pub bldg_nm: Option<String>,
1777    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
1778    pub flr: Option<String>,
1779    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
1780    pub pst_bx: Option<String>,
1781    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
1782    pub room: Option<String>,
1783    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
1784    pub pst_cd: Option<String>,
1785    #[serde(rename = "TwnNm")]
1786    pub twn_nm: String,
1787    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
1788    pub twn_lctn_nm: Option<String>,
1789    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
1790    pub dstrct_nm: Option<String>,
1791    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
1792    pub ctry_sub_dvsn: Option<String>,
1793    #[serde(rename = "Ctry")]
1794    pub ctry: String,
1795    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
1796    pub adr_line: Option<Vec<String>>,
1797}
1798
1799impl PostalAddress241 {
1800    pub fn validate(&self) -> Result<(), ValidationError> {
1801        if let Some(ref val) = self.dept {
1802            if val.chars().count() < 1 {
1803                return Err(ValidationError::new(
1804                    1001,
1805                    "dept is shorter than the minimum length of 1".to_string(),
1806                ));
1807            }
1808            if val.chars().count() > 70 {
1809                return Err(ValidationError::new(
1810                    1002,
1811                    "dept exceeds the maximum length of 70".to_string(),
1812                ));
1813            }
1814            let pattern = Regex::new(
1815                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1816            )
1817            .unwrap();
1818            if !pattern.is_match(val) {
1819                return Err(ValidationError::new(
1820                    1005,
1821                    "dept does not match the required pattern".to_string(),
1822                ));
1823            }
1824        }
1825        if let Some(ref val) = self.sub_dept {
1826            if val.chars().count() < 1 {
1827                return Err(ValidationError::new(
1828                    1001,
1829                    "sub_dept is shorter than the minimum length of 1".to_string(),
1830                ));
1831            }
1832            if val.chars().count() > 70 {
1833                return Err(ValidationError::new(
1834                    1002,
1835                    "sub_dept exceeds the maximum length of 70".to_string(),
1836                ));
1837            }
1838            let pattern = Regex::new(
1839                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1840            )
1841            .unwrap();
1842            if !pattern.is_match(val) {
1843                return Err(ValidationError::new(
1844                    1005,
1845                    "sub_dept does not match the required pattern".to_string(),
1846                ));
1847            }
1848        }
1849        if let Some(ref val) = self.strt_nm {
1850            if val.chars().count() < 1 {
1851                return Err(ValidationError::new(
1852                    1001,
1853                    "strt_nm is shorter than the minimum length of 1".to_string(),
1854                ));
1855            }
1856            if val.chars().count() > 70 {
1857                return Err(ValidationError::new(
1858                    1002,
1859                    "strt_nm exceeds the maximum length of 70".to_string(),
1860                ));
1861            }
1862            let pattern = Regex::new(
1863                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1864            )
1865            .unwrap();
1866            if !pattern.is_match(val) {
1867                return Err(ValidationError::new(
1868                    1005,
1869                    "strt_nm does not match the required pattern".to_string(),
1870                ));
1871            }
1872        }
1873        if let Some(ref val) = self.bldg_nb {
1874            if val.chars().count() < 1 {
1875                return Err(ValidationError::new(
1876                    1001,
1877                    "bldg_nb is shorter than the minimum length of 1".to_string(),
1878                ));
1879            }
1880            if val.chars().count() > 16 {
1881                return Err(ValidationError::new(
1882                    1002,
1883                    "bldg_nb exceeds the maximum length of 16".to_string(),
1884                ));
1885            }
1886            let pattern = Regex::new(
1887                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1888            )
1889            .unwrap();
1890            if !pattern.is_match(val) {
1891                return Err(ValidationError::new(
1892                    1005,
1893                    "bldg_nb does not match the required pattern".to_string(),
1894                ));
1895            }
1896        }
1897        if let Some(ref val) = self.bldg_nm {
1898            if val.chars().count() < 1 {
1899                return Err(ValidationError::new(
1900                    1001,
1901                    "bldg_nm is shorter than the minimum length of 1".to_string(),
1902                ));
1903            }
1904            if val.chars().count() > 35 {
1905                return Err(ValidationError::new(
1906                    1002,
1907                    "bldg_nm exceeds the maximum length of 35".to_string(),
1908                ));
1909            }
1910            let pattern = Regex::new(
1911                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1912            )
1913            .unwrap();
1914            if !pattern.is_match(val) {
1915                return Err(ValidationError::new(
1916                    1005,
1917                    "bldg_nm does not match the required pattern".to_string(),
1918                ));
1919            }
1920        }
1921        if let Some(ref val) = self.flr {
1922            if val.chars().count() < 1 {
1923                return Err(ValidationError::new(
1924                    1001,
1925                    "flr is shorter than the minimum length of 1".to_string(),
1926                ));
1927            }
1928            if val.chars().count() > 70 {
1929                return Err(ValidationError::new(
1930                    1002,
1931                    "flr exceeds the maximum length of 70".to_string(),
1932                ));
1933            }
1934            let pattern = Regex::new(
1935                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1936            )
1937            .unwrap();
1938            if !pattern.is_match(val) {
1939                return Err(ValidationError::new(
1940                    1005,
1941                    "flr does not match the required pattern".to_string(),
1942                ));
1943            }
1944        }
1945        if let Some(ref val) = self.pst_bx {
1946            if val.chars().count() < 1 {
1947                return Err(ValidationError::new(
1948                    1001,
1949                    "pst_bx is shorter than the minimum length of 1".to_string(),
1950                ));
1951            }
1952            if val.chars().count() > 16 {
1953                return Err(ValidationError::new(
1954                    1002,
1955                    "pst_bx exceeds the maximum length of 16".to_string(),
1956                ));
1957            }
1958            let pattern = Regex::new(
1959                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1960            )
1961            .unwrap();
1962            if !pattern.is_match(val) {
1963                return Err(ValidationError::new(
1964                    1005,
1965                    "pst_bx does not match the required pattern".to_string(),
1966                ));
1967            }
1968        }
1969        if let Some(ref val) = self.room {
1970            if val.chars().count() < 1 {
1971                return Err(ValidationError::new(
1972                    1001,
1973                    "room is shorter than the minimum length of 1".to_string(),
1974                ));
1975            }
1976            if val.chars().count() > 70 {
1977                return Err(ValidationError::new(
1978                    1002,
1979                    "room exceeds the maximum length of 70".to_string(),
1980                ));
1981            }
1982            let pattern = Regex::new(
1983                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1984            )
1985            .unwrap();
1986            if !pattern.is_match(val) {
1987                return Err(ValidationError::new(
1988                    1005,
1989                    "room does not match the required pattern".to_string(),
1990                ));
1991            }
1992        }
1993        if let Some(ref val) = self.pst_cd {
1994            if val.chars().count() < 1 {
1995                return Err(ValidationError::new(
1996                    1001,
1997                    "pst_cd is shorter than the minimum length of 1".to_string(),
1998                ));
1999            }
2000            if val.chars().count() > 16 {
2001                return Err(ValidationError::new(
2002                    1002,
2003                    "pst_cd exceeds the maximum length of 16".to_string(),
2004                ));
2005            }
2006            let pattern = Regex::new(
2007                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2008            )
2009            .unwrap();
2010            if !pattern.is_match(val) {
2011                return Err(ValidationError::new(
2012                    1005,
2013                    "pst_cd does not match the required pattern".to_string(),
2014                ));
2015            }
2016        }
2017        if self.twn_nm.chars().count() < 1 {
2018            return Err(ValidationError::new(
2019                1001,
2020                "twn_nm is shorter than the minimum length of 1".to_string(),
2021            ));
2022        }
2023        if self.twn_nm.chars().count() > 35 {
2024            return Err(ValidationError::new(
2025                1002,
2026                "twn_nm exceeds the maximum length of 35".to_string(),
2027            ));
2028        }
2029        let pattern =
2030            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
2031                .unwrap();
2032        if !pattern.is_match(&self.twn_nm) {
2033            return Err(ValidationError::new(
2034                1005,
2035                "twn_nm does not match the required pattern".to_string(),
2036            ));
2037        }
2038        if let Some(ref val) = self.twn_lctn_nm {
2039            if val.chars().count() < 1 {
2040                return Err(ValidationError::new(
2041                    1001,
2042                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
2043                ));
2044            }
2045            if val.chars().count() > 35 {
2046                return Err(ValidationError::new(
2047                    1002,
2048                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
2049                ));
2050            }
2051            let pattern = Regex::new(
2052                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2053            )
2054            .unwrap();
2055            if !pattern.is_match(val) {
2056                return Err(ValidationError::new(
2057                    1005,
2058                    "twn_lctn_nm does not match the required pattern".to_string(),
2059                ));
2060            }
2061        }
2062        if let Some(ref val) = self.dstrct_nm {
2063            if val.chars().count() < 1 {
2064                return Err(ValidationError::new(
2065                    1001,
2066                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
2067                ));
2068            }
2069            if val.chars().count() > 35 {
2070                return Err(ValidationError::new(
2071                    1002,
2072                    "dstrct_nm exceeds the maximum length of 35".to_string(),
2073                ));
2074            }
2075            let pattern = Regex::new(
2076                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2077            )
2078            .unwrap();
2079            if !pattern.is_match(val) {
2080                return Err(ValidationError::new(
2081                    1005,
2082                    "dstrct_nm does not match the required pattern".to_string(),
2083                ));
2084            }
2085        }
2086        if let Some(ref val) = self.ctry_sub_dvsn {
2087            if val.chars().count() < 1 {
2088                return Err(ValidationError::new(
2089                    1001,
2090                    "ctry_sub_dvsn 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                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
2097                ));
2098            }
2099            let pattern = Regex::new(
2100                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2101            )
2102            .unwrap();
2103            if !pattern.is_match(val) {
2104                return Err(ValidationError::new(
2105                    1005,
2106                    "ctry_sub_dvsn does not match the required pattern".to_string(),
2107                ));
2108            }
2109        }
2110        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
2111        if !pattern.is_match(&self.ctry) {
2112            return Err(ValidationError::new(
2113                1005,
2114                "ctry does not match the required pattern".to_string(),
2115            ));
2116        }
2117        if let Some(ref vec) = self.adr_line {
2118            for item in vec {
2119                if item.chars().count() < 1 {
2120                    return Err(ValidationError::new(
2121                        1001,
2122                        "adr_line is shorter than the minimum length of 1".to_string(),
2123                    ));
2124                }
2125                if item.chars().count() > 70 {
2126                    return Err(ValidationError::new(
2127                        1002,
2128                        "adr_line exceeds the maximum length of 70".to_string(),
2129                    ));
2130                }
2131                let pattern = Regex::new(
2132                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2133                )
2134                .unwrap();
2135                if !pattern.is_match(&item) {
2136                    return Err(ValidationError::new(
2137                        1005,
2138                        "adr_line does not match the required pattern".to_string(),
2139                    ));
2140                }
2141            }
2142        }
2143        Ok(())
2144    }
2145}
2146
2147// PostalAddress242: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
2148#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2149pub struct PostalAddress242 {
2150    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
2151    pub dept: Option<String>,
2152    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
2153    pub sub_dept: Option<String>,
2154    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
2155    pub strt_nm: Option<String>,
2156    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
2157    pub bldg_nb: Option<String>,
2158    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
2159    pub bldg_nm: Option<String>,
2160    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
2161    pub flr: Option<String>,
2162    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
2163    pub pst_bx: Option<String>,
2164    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
2165    pub room: Option<String>,
2166    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
2167    pub pst_cd: Option<String>,
2168    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
2169    pub twn_nm: Option<String>,
2170    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
2171    pub twn_lctn_nm: Option<String>,
2172    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
2173    pub dstrct_nm: Option<String>,
2174    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
2175    pub ctry_sub_dvsn: Option<String>,
2176    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
2177    pub ctry: Option<String>,
2178    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
2179    pub adr_line: Option<Vec<String>>,
2180}
2181
2182impl PostalAddress242 {
2183    pub fn validate(&self) -> Result<(), ValidationError> {
2184        if let Some(ref val) = self.dept {
2185            if val.chars().count() < 1 {
2186                return Err(ValidationError::new(
2187                    1001,
2188                    "dept is shorter than the minimum length of 1".to_string(),
2189                ));
2190            }
2191            if val.chars().count() > 70 {
2192                return Err(ValidationError::new(
2193                    1002,
2194                    "dept exceeds the maximum length of 70".to_string(),
2195                ));
2196            }
2197            let pattern = Regex::new(
2198                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2199            )
2200            .unwrap();
2201            if !pattern.is_match(val) {
2202                return Err(ValidationError::new(
2203                    1005,
2204                    "dept does not match the required pattern".to_string(),
2205                ));
2206            }
2207        }
2208        if let Some(ref val) = self.sub_dept {
2209            if val.chars().count() < 1 {
2210                return Err(ValidationError::new(
2211                    1001,
2212                    "sub_dept is shorter than the minimum length of 1".to_string(),
2213                ));
2214            }
2215            if val.chars().count() > 70 {
2216                return Err(ValidationError::new(
2217                    1002,
2218                    "sub_dept exceeds the maximum length of 70".to_string(),
2219                ));
2220            }
2221            let pattern = Regex::new(
2222                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2223            )
2224            .unwrap();
2225            if !pattern.is_match(val) {
2226                return Err(ValidationError::new(
2227                    1005,
2228                    "sub_dept does not match the required pattern".to_string(),
2229                ));
2230            }
2231        }
2232        if let Some(ref val) = self.strt_nm {
2233            if val.chars().count() < 1 {
2234                return Err(ValidationError::new(
2235                    1001,
2236                    "strt_nm is shorter than the minimum length of 1".to_string(),
2237                ));
2238            }
2239            if val.chars().count() > 70 {
2240                return Err(ValidationError::new(
2241                    1002,
2242                    "strt_nm exceeds the maximum length of 70".to_string(),
2243                ));
2244            }
2245            let pattern = Regex::new(
2246                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2247            )
2248            .unwrap();
2249            if !pattern.is_match(val) {
2250                return Err(ValidationError::new(
2251                    1005,
2252                    "strt_nm does not match the required pattern".to_string(),
2253                ));
2254            }
2255        }
2256        if let Some(ref val) = self.bldg_nb {
2257            if val.chars().count() < 1 {
2258                return Err(ValidationError::new(
2259                    1001,
2260                    "bldg_nb is shorter than the minimum length of 1".to_string(),
2261                ));
2262            }
2263            if val.chars().count() > 16 {
2264                return Err(ValidationError::new(
2265                    1002,
2266                    "bldg_nb exceeds the maximum length of 16".to_string(),
2267                ));
2268            }
2269            let pattern = Regex::new(
2270                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2271            )
2272            .unwrap();
2273            if !pattern.is_match(val) {
2274                return Err(ValidationError::new(
2275                    1005,
2276                    "bldg_nb does not match the required pattern".to_string(),
2277                ));
2278            }
2279        }
2280        if let Some(ref val) = self.bldg_nm {
2281            if val.chars().count() < 1 {
2282                return Err(ValidationError::new(
2283                    1001,
2284                    "bldg_nm is shorter than the minimum length of 1".to_string(),
2285                ));
2286            }
2287            if val.chars().count() > 35 {
2288                return Err(ValidationError::new(
2289                    1002,
2290                    "bldg_nm exceeds the maximum length of 35".to_string(),
2291                ));
2292            }
2293            let pattern = Regex::new(
2294                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2295            )
2296            .unwrap();
2297            if !pattern.is_match(val) {
2298                return Err(ValidationError::new(
2299                    1005,
2300                    "bldg_nm does not match the required pattern".to_string(),
2301                ));
2302            }
2303        }
2304        if let Some(ref val) = self.flr {
2305            if val.chars().count() < 1 {
2306                return Err(ValidationError::new(
2307                    1001,
2308                    "flr is shorter than the minimum length of 1".to_string(),
2309                ));
2310            }
2311            if val.chars().count() > 70 {
2312                return Err(ValidationError::new(
2313                    1002,
2314                    "flr exceeds the maximum length of 70".to_string(),
2315                ));
2316            }
2317            let pattern = Regex::new(
2318                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2319            )
2320            .unwrap();
2321            if !pattern.is_match(val) {
2322                return Err(ValidationError::new(
2323                    1005,
2324                    "flr does not match the required pattern".to_string(),
2325                ));
2326            }
2327        }
2328        if let Some(ref val) = self.pst_bx {
2329            if val.chars().count() < 1 {
2330                return Err(ValidationError::new(
2331                    1001,
2332                    "pst_bx is shorter than the minimum length of 1".to_string(),
2333                ));
2334            }
2335            if val.chars().count() > 16 {
2336                return Err(ValidationError::new(
2337                    1002,
2338                    "pst_bx exceeds the maximum length of 16".to_string(),
2339                ));
2340            }
2341            let pattern = Regex::new(
2342                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2343            )
2344            .unwrap();
2345            if !pattern.is_match(val) {
2346                return Err(ValidationError::new(
2347                    1005,
2348                    "pst_bx does not match the required pattern".to_string(),
2349                ));
2350            }
2351        }
2352        if let Some(ref val) = self.room {
2353            if val.chars().count() < 1 {
2354                return Err(ValidationError::new(
2355                    1001,
2356                    "room is shorter than the minimum length of 1".to_string(),
2357                ));
2358            }
2359            if val.chars().count() > 70 {
2360                return Err(ValidationError::new(
2361                    1002,
2362                    "room exceeds the maximum length of 70".to_string(),
2363                ));
2364            }
2365            let pattern = Regex::new(
2366                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2367            )
2368            .unwrap();
2369            if !pattern.is_match(val) {
2370                return Err(ValidationError::new(
2371                    1005,
2372                    "room does not match the required pattern".to_string(),
2373                ));
2374            }
2375        }
2376        if let Some(ref val) = self.pst_cd {
2377            if val.chars().count() < 1 {
2378                return Err(ValidationError::new(
2379                    1001,
2380                    "pst_cd is shorter than the minimum length of 1".to_string(),
2381                ));
2382            }
2383            if val.chars().count() > 16 {
2384                return Err(ValidationError::new(
2385                    1002,
2386                    "pst_cd exceeds the maximum length of 16".to_string(),
2387                ));
2388            }
2389            let pattern = Regex::new(
2390                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2391            )
2392            .unwrap();
2393            if !pattern.is_match(val) {
2394                return Err(ValidationError::new(
2395                    1005,
2396                    "pst_cd does not match the required pattern".to_string(),
2397                ));
2398            }
2399        }
2400        if let Some(ref val) = self.twn_nm {
2401            if val.chars().count() < 1 {
2402                return Err(ValidationError::new(
2403                    1001,
2404                    "twn_nm is shorter than the minimum length of 1".to_string(),
2405                ));
2406            }
2407            if val.chars().count() > 35 {
2408                return Err(ValidationError::new(
2409                    1002,
2410                    "twn_nm exceeds the maximum length of 35".to_string(),
2411                ));
2412            }
2413            let pattern = Regex::new(
2414                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2415            )
2416            .unwrap();
2417            if !pattern.is_match(val) {
2418                return Err(ValidationError::new(
2419                    1005,
2420                    "twn_nm does not match the required pattern".to_string(),
2421                ));
2422            }
2423        }
2424        if let Some(ref val) = self.twn_lctn_nm {
2425            if val.chars().count() < 1 {
2426                return Err(ValidationError::new(
2427                    1001,
2428                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
2429                ));
2430            }
2431            if val.chars().count() > 35 {
2432                return Err(ValidationError::new(
2433                    1002,
2434                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
2435                ));
2436            }
2437            let pattern = Regex::new(
2438                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2439            )
2440            .unwrap();
2441            if !pattern.is_match(val) {
2442                return Err(ValidationError::new(
2443                    1005,
2444                    "twn_lctn_nm does not match the required pattern".to_string(),
2445                ));
2446            }
2447        }
2448        if let Some(ref val) = self.dstrct_nm {
2449            if val.chars().count() < 1 {
2450                return Err(ValidationError::new(
2451                    1001,
2452                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
2453                ));
2454            }
2455            if val.chars().count() > 35 {
2456                return Err(ValidationError::new(
2457                    1002,
2458                    "dstrct_nm exceeds the maximum length of 35".to_string(),
2459                ));
2460            }
2461            let pattern = Regex::new(
2462                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2463            )
2464            .unwrap();
2465            if !pattern.is_match(val) {
2466                return Err(ValidationError::new(
2467                    1005,
2468                    "dstrct_nm does not match the required pattern".to_string(),
2469                ));
2470            }
2471        }
2472        if let Some(ref val) = self.ctry_sub_dvsn {
2473            if val.chars().count() < 1 {
2474                return Err(ValidationError::new(
2475                    1001,
2476                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
2477                ));
2478            }
2479            if val.chars().count() > 35 {
2480                return Err(ValidationError::new(
2481                    1002,
2482                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
2483                ));
2484            }
2485            let pattern = Regex::new(
2486                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2487            )
2488            .unwrap();
2489            if !pattern.is_match(val) {
2490                return Err(ValidationError::new(
2491                    1005,
2492                    "ctry_sub_dvsn does not match the required pattern".to_string(),
2493                ));
2494            }
2495        }
2496        if let Some(ref val) = self.ctry {
2497            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
2498            if !pattern.is_match(val) {
2499                return Err(ValidationError::new(
2500                    1005,
2501                    "ctry does not match the required pattern".to_string(),
2502                ));
2503            }
2504        }
2505        if let Some(ref vec) = self.adr_line {
2506            for item in vec {
2507                if item.chars().count() < 1 {
2508                    return Err(ValidationError::new(
2509                        1001,
2510                        "adr_line is shorter than the minimum length of 1".to_string(),
2511                    ));
2512                }
2513                if item.chars().count() > 70 {
2514                    return Err(ValidationError::new(
2515                        1002,
2516                        "adr_line exceeds the maximum length of 70".to_string(),
2517                    ));
2518                }
2519                let pattern = Regex::new(
2520                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2521                )
2522                .unwrap();
2523                if !pattern.is_match(&item) {
2524                    return Err(ValidationError::new(
2525                        1005,
2526                        "adr_line does not match the required pattern".to_string(),
2527                    ));
2528                }
2529            }
2530        }
2531        Ok(())
2532    }
2533}
2534
2535// Priority2Code: Priority level is normal.
2536#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2537pub enum Priority2Code {
2538    #[default]
2539    #[serde(rename = "HIGH")]
2540    CodeHIGH,
2541    #[serde(rename = "NORM")]
2542    CodeNORM,
2543}
2544
2545impl Priority2Code {
2546    pub fn validate(&self) -> Result<(), ValidationError> {
2547        Ok(())
2548    }
2549}
2550
2551// Priority3Code: Priority level is normal.
2552#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2553pub enum Priority3Code {
2554    #[default]
2555    #[serde(rename = "URGT")]
2556    CodeURGT,
2557    #[serde(rename = "HIGH")]
2558    CodeHIGH,
2559    #[serde(rename = "NORM")]
2560    CodeNORM,
2561}
2562
2563impl Priority3Code {
2564    pub fn validate(&self) -> Result<(), ValidationError> {
2565        Ok(())
2566    }
2567}
2568
2569// ProxyAccountIdentification11: Identification used to indicate the account identification under another specified name.
2570#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2571pub struct ProxyAccountIdentification11 {
2572    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
2573    pub tp: Option<ProxyAccountType1Choice1>,
2574    #[serde(rename = "Id")]
2575    pub id: String,
2576}
2577
2578impl ProxyAccountIdentification11 {
2579    pub fn validate(&self) -> Result<(), ValidationError> {
2580        if let Some(ref val) = self.tp {
2581            val.validate()?
2582        }
2583        if self.id.chars().count() < 1 {
2584            return Err(ValidationError::new(
2585                1001,
2586                "id is shorter than the minimum length of 1".to_string(),
2587            ));
2588        }
2589        if self.id.chars().count() > 320 {
2590            return Err(ValidationError::new(
2591                1002,
2592                "id exceeds the maximum length of 320".to_string(),
2593            ));
2594        }
2595        let pattern =
2596            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
2597                .unwrap();
2598        if !pattern.is_match(&self.id) {
2599            return Err(ValidationError::new(
2600                1005,
2601                "id does not match the required pattern".to_string(),
2602            ));
2603        }
2604        Ok(())
2605    }
2606}
2607
2608// ProxyAccountType1Choice1: Name of the identification scheme, in a free text form.
2609#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2610pub struct ProxyAccountType1Choice1 {
2611    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2612    pub cd: Option<String>,
2613    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
2614    pub prtry: Option<String>,
2615}
2616
2617impl ProxyAccountType1Choice1 {
2618    pub fn validate(&self) -> Result<(), ValidationError> {
2619        if let Some(ref val) = self.cd {
2620            if val.chars().count() < 1 {
2621                return Err(ValidationError::new(
2622                    1001,
2623                    "cd is shorter than the minimum length of 1".to_string(),
2624                ));
2625            }
2626            if val.chars().count() > 4 {
2627                return Err(ValidationError::new(
2628                    1002,
2629                    "cd exceeds the maximum length of 4".to_string(),
2630                ));
2631            }
2632        }
2633        if let Some(ref val) = self.prtry {
2634            if val.chars().count() < 1 {
2635                return Err(ValidationError::new(
2636                    1001,
2637                    "prtry is shorter than the minimum length of 1".to_string(),
2638                ));
2639            }
2640            if val.chars().count() > 35 {
2641                return Err(ValidationError::new(
2642                    1002,
2643                    "prtry exceeds the maximum length of 35".to_string(),
2644                ));
2645            }
2646            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
2647            if !pattern.is_match(val) {
2648                return Err(ValidationError::new(
2649                    1005,
2650                    "prtry does not match the required pattern".to_string(),
2651                ));
2652            }
2653        }
2654        Ok(())
2655    }
2656}
2657
2658// Purpose2Choice1: Underlying reason for the payment transaction, as published in an external purpose code list.
2659#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2660pub struct Purpose2Choice1 {
2661    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2662    pub cd: Option<String>,
2663}
2664
2665impl Purpose2Choice1 {
2666    pub fn validate(&self) -> Result<(), ValidationError> {
2667        if let Some(ref val) = self.cd {
2668            if val.chars().count() < 1 {
2669                return Err(ValidationError::new(
2670                    1001,
2671                    "cd is shorter than the minimum length of 1".to_string(),
2672                ));
2673            }
2674            if val.chars().count() > 4 {
2675                return Err(ValidationError::new(
2676                    1002,
2677                    "cd exceeds the maximum length of 4".to_string(),
2678                ));
2679            }
2680        }
2681        Ok(())
2682    }
2683}
2684
2685// RegulatoryAuthority21: Country of the entity that requires the regulatory reporting information.
2686#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2687pub struct RegulatoryAuthority21 {
2688    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
2689    pub nm: Option<String>,
2690    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
2691    pub ctry: Option<String>,
2692}
2693
2694impl RegulatoryAuthority21 {
2695    pub fn validate(&self) -> Result<(), ValidationError> {
2696        if let Some(ref val) = self.nm {
2697            if val.chars().count() < 1 {
2698                return Err(ValidationError::new(
2699                    1001,
2700                    "nm is shorter than the minimum length of 1".to_string(),
2701                ));
2702            }
2703            if val.chars().count() > 140 {
2704                return Err(ValidationError::new(
2705                    1002,
2706                    "nm exceeds the maximum length of 140".to_string(),
2707                ));
2708            }
2709            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
2710            if !pattern.is_match(val) {
2711                return Err(ValidationError::new(
2712                    1005,
2713                    "nm does not match the required pattern".to_string(),
2714                ));
2715            }
2716        }
2717        if let Some(ref val) = self.ctry {
2718            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
2719            if !pattern.is_match(val) {
2720                return Err(ValidationError::new(
2721                    1005,
2722                    "ctry does not match the required pattern".to_string(),
2723                ));
2724            }
2725        }
2726        Ok(())
2727    }
2728}
2729
2730// RegulatoryReporting31: Set of elements used to provide details on the regulatory reporting information.
2731#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2732pub struct RegulatoryReporting31 {
2733    #[serde(rename = "DbtCdtRptgInd", skip_serializing_if = "Option::is_none")]
2734    pub dbt_cdt_rptg_ind: Option<RegulatoryReportingType1Code>,
2735    #[serde(rename = "Authrty", skip_serializing_if = "Option::is_none")]
2736    pub authrty: Option<RegulatoryAuthority21>,
2737    #[serde(rename = "Dtls", skip_serializing_if = "Option::is_none")]
2738    pub dtls: Option<Vec<StructuredRegulatoryReporting31>>,
2739}
2740
2741impl RegulatoryReporting31 {
2742    pub fn validate(&self) -> Result<(), ValidationError> {
2743        if let Some(ref val) = self.dbt_cdt_rptg_ind {
2744            val.validate()?
2745        }
2746        if let Some(ref val) = self.authrty {
2747            val.validate()?
2748        }
2749        if let Some(ref vec) = self.dtls {
2750            for item in vec {
2751                item.validate()?
2752            }
2753        }
2754        Ok(())
2755    }
2756}
2757
2758// RegulatoryReportingType1Code: Regulatory information applies to both credit and debit sides.
2759#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2760pub enum RegulatoryReportingType1Code {
2761    #[default]
2762    #[serde(rename = "CRED")]
2763    CodeCRED,
2764    #[serde(rename = "DEBT")]
2765    CodeDEBT,
2766    #[serde(rename = "BOTH")]
2767    CodeBOTH,
2768}
2769
2770impl RegulatoryReportingType1Code {
2771    pub fn validate(&self) -> Result<(), ValidationError> {
2772        Ok(())
2773    }
2774}
2775
2776// 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 an unstructured form.
2777#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2778pub struct RemittanceInformation161 {
2779    #[serde(rename = "Ustrd", skip_serializing_if = "Option::is_none")]
2780    pub ustrd: Option<String>,
2781}
2782
2783impl RemittanceInformation161 {
2784    pub fn validate(&self) -> Result<(), ValidationError> {
2785        if let Some(ref val) = self.ustrd {
2786            if val.chars().count() < 1 {
2787                return Err(ValidationError::new(
2788                    1001,
2789                    "ustrd is shorter than the minimum length of 1".to_string(),
2790                ));
2791            }
2792            if val.chars().count() > 140 {
2793                return Err(ValidationError::new(
2794                    1002,
2795                    "ustrd exceeds the maximum length of 140".to_string(),
2796                ));
2797            }
2798            let pattern = Regex::new(
2799                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2800            )
2801            .unwrap();
2802            if !pattern.is_match(val) {
2803                return Err(ValidationError::new(
2804                    1005,
2805                    "ustrd does not match the required pattern".to_string(),
2806                ));
2807            }
2808        }
2809        Ok(())
2810    }
2811}
2812
2813// RemittanceLocation71: Set of elements used to provide information on the location and/or delivery of the remittance information.
2814#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2815pub struct RemittanceLocation71 {
2816    #[serde(rename = "RmtId", skip_serializing_if = "Option::is_none")]
2817    pub rmt_id: Option<String>,
2818    #[serde(rename = "RmtLctnDtls", skip_serializing_if = "Option::is_none")]
2819    pub rmt_lctn_dtls: Option<Vec<RemittanceLocationData11>>,
2820}
2821
2822impl RemittanceLocation71 {
2823    pub fn validate(&self) -> Result<(), ValidationError> {
2824        if let Some(ref val) = self.rmt_id {
2825            if val.chars().count() < 1 {
2826                return Err(ValidationError::new(
2827                    1001,
2828                    "rmt_id is shorter than the minimum length of 1".to_string(),
2829                ));
2830            }
2831            if val.chars().count() > 35 {
2832                return Err(ValidationError::new(
2833                    1002,
2834                    "rmt_id exceeds the maximum length of 35".to_string(),
2835                ));
2836            }
2837            let pattern = Regex::new(
2838                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2839            )
2840            .unwrap();
2841            if !pattern.is_match(val) {
2842                return Err(ValidationError::new(
2843                    1005,
2844                    "rmt_id does not match the required pattern".to_string(),
2845                ));
2846            }
2847        }
2848        if let Some(ref vec) = self.rmt_lctn_dtls {
2849            for item in vec {
2850                item.validate()?
2851            }
2852        }
2853        Ok(())
2854    }
2855}
2856
2857// RemittanceLocationData11: Postal address to which an agent is to send the remittance information.
2858#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2859pub struct RemittanceLocationData11 {
2860    #[serde(rename = "Mtd")]
2861    pub mtd: RemittanceLocationMethod2Code,
2862    #[serde(rename = "ElctrncAdr", skip_serializing_if = "Option::is_none")]
2863    pub elctrnc_adr: Option<String>,
2864    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
2865    pub pstl_adr: Option<NameAndAddress161>,
2866}
2867
2868impl RemittanceLocationData11 {
2869    pub fn validate(&self) -> Result<(), ValidationError> {
2870        self.mtd.validate()?;
2871        if let Some(ref val) = self.elctrnc_adr {
2872            if val.chars().count() < 1 {
2873                return Err(ValidationError::new(
2874                    1001,
2875                    "elctrnc_adr is shorter than the minimum length of 1".to_string(),
2876                ));
2877            }
2878            if val.chars().count() > 2048 {
2879                return Err(ValidationError::new(
2880                    1002,
2881                    "elctrnc_adr exceeds the maximum length of 2048".to_string(),
2882                ));
2883            }
2884            let pattern = Regex::new(
2885                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
2886            )
2887            .unwrap();
2888            if !pattern.is_match(val) {
2889                return Err(ValidationError::new(
2890                    1005,
2891                    "elctrnc_adr does not match the required pattern".to_string(),
2892                ));
2893            }
2894        }
2895        if let Some(ref val) = self.pstl_adr {
2896            val.validate()?
2897        }
2898        Ok(())
2899    }
2900}
2901
2902// RemittanceLocationMethod2Code: Remittance advice information must be sent through by phone as a short message service (SMS).
2903#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2904pub enum RemittanceLocationMethod2Code {
2905    #[default]
2906    #[serde(rename = "FAXI")]
2907    CodeFAXI,
2908    #[serde(rename = "EDIC")]
2909    CodeEDIC,
2910    #[serde(rename = "URID")]
2911    CodeURID,
2912    #[serde(rename = "EMAL")]
2913    CodeEMAL,
2914    #[serde(rename = "POST")]
2915    CodePOST,
2916    #[serde(rename = "SMSM")]
2917    CodeSMSM,
2918}
2919
2920impl RemittanceLocationMethod2Code {
2921    pub fn validate(&self) -> Result<(), ValidationError> {
2922        Ok(())
2923    }
2924}
2925
2926// ServiceLevel8Choice1: Specifies a pre-agreed service or level of service between the parties, as published in an external service level code list.
2927#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2928pub struct ServiceLevel8Choice1 {
2929    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
2930    pub cd: Option<String>,
2931}
2932
2933impl ServiceLevel8Choice1 {
2934    pub fn validate(&self) -> Result<(), ValidationError> {
2935        if let Some(ref val) = self.cd {
2936            if val.chars().count() < 1 {
2937                return Err(ValidationError::new(
2938                    1001,
2939                    "cd is shorter than the minimum length of 1".to_string(),
2940                ));
2941            }
2942            if val.chars().count() > 4 {
2943                return Err(ValidationError::new(
2944                    1002,
2945                    "cd exceeds the maximum length of 4".to_string(),
2946                ));
2947            }
2948        }
2949        Ok(())
2950    }
2951}
2952
2953// SettlementDateTimeIndication11: Date and time at which a payment has been credited at the transaction administrator. In the case of TARGET, the date and time at which the payment has been credited at the receiving central bank, expressed in Central European Time (CET).
2954#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2955pub struct SettlementDateTimeIndication11 {
2956    #[serde(rename = "DbtDtTm", skip_serializing_if = "Option::is_none")]
2957    pub dbt_dt_tm: Option<String>,
2958    #[serde(rename = "CdtDtTm", skip_serializing_if = "Option::is_none")]
2959    pub cdt_dt_tm: Option<String>,
2960}
2961
2962impl SettlementDateTimeIndication11 {
2963    pub fn validate(&self) -> Result<(), ValidationError> {
2964        if let Some(ref val) = self.dbt_dt_tm {
2965            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
2966            if !pattern.is_match(val) {
2967                return Err(ValidationError::new(
2968                    1005,
2969                    "dbt_dt_tm does not match the required pattern".to_string(),
2970                ));
2971            }
2972        }
2973        if let Some(ref val) = self.cdt_dt_tm {
2974            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
2975            if !pattern.is_match(val) {
2976                return Err(ValidationError::new(
2977                    1005,
2978                    "cdt_dt_tm does not match the required pattern".to_string(),
2979                ));
2980            }
2981        }
2982        Ok(())
2983    }
2984}
2985
2986// SettlementInstruction71: Unambiguous identification of the account of the third reimbursement agent account at its servicing agent in the payment chain.
2987#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
2988pub struct SettlementInstruction71 {
2989    #[serde(rename = "SttlmMtd")]
2990    pub sttlm_mtd: SettlementMethod1Code1,
2991    #[serde(rename = "SttlmAcct", skip_serializing_if = "Option::is_none")]
2992    pub sttlm_acct: Option<CashAccount381>,
2993    #[serde(rename = "InstgRmbrsmntAgt", skip_serializing_if = "Option::is_none")]
2994    pub instg_rmbrsmnt_agt: Option<BranchAndFinancialInstitutionIdentification61>,
2995    #[serde(
2996        rename = "InstgRmbrsmntAgtAcct",
2997        skip_serializing_if = "Option::is_none"
2998    )]
2999    pub instg_rmbrsmnt_agt_acct: Option<CashAccount381>,
3000    #[serde(rename = "InstdRmbrsmntAgt", skip_serializing_if = "Option::is_none")]
3001    pub instd_rmbrsmnt_agt: Option<BranchAndFinancialInstitutionIdentification61>,
3002    #[serde(
3003        rename = "InstdRmbrsmntAgtAcct",
3004        skip_serializing_if = "Option::is_none"
3005    )]
3006    pub instd_rmbrsmnt_agt_acct: Option<CashAccount381>,
3007    #[serde(rename = "ThrdRmbrsmntAgt", skip_serializing_if = "Option::is_none")]
3008    pub thrd_rmbrsmnt_agt: Option<BranchAndFinancialInstitutionIdentification61>,
3009    #[serde(
3010        rename = "ThrdRmbrsmntAgtAcct",
3011        skip_serializing_if = "Option::is_none"
3012    )]
3013    pub thrd_rmbrsmnt_agt_acct: Option<CashAccount381>,
3014}
3015
3016impl SettlementInstruction71 {
3017    pub fn validate(&self) -> Result<(), ValidationError> {
3018        self.sttlm_mtd.validate()?;
3019        if let Some(ref val) = self.sttlm_acct {
3020            val.validate()?
3021        }
3022        if let Some(ref val) = self.instg_rmbrsmnt_agt {
3023            val.validate()?
3024        }
3025        if let Some(ref val) = self.instg_rmbrsmnt_agt_acct {
3026            val.validate()?
3027        }
3028        if let Some(ref val) = self.instd_rmbrsmnt_agt {
3029            val.validate()?
3030        }
3031        if let Some(ref val) = self.instd_rmbrsmnt_agt_acct {
3032            val.validate()?
3033        }
3034        if let Some(ref val) = self.thrd_rmbrsmnt_agt {
3035            val.validate()?
3036        }
3037        if let Some(ref val) = self.thrd_rmbrsmnt_agt_acct {
3038            val.validate()?
3039        }
3040        Ok(())
3041    }
3042}
3043
3044// SettlementMethod1Code__1: Settlement is done through a cover payment.
3045#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3046pub enum SettlementMethod1Code1 {
3047    #[default]
3048    #[serde(rename = "INDA")]
3049    CodeINDA,
3050    #[serde(rename = "INGA")]
3051    CodeINGA,
3052    #[serde(rename = "COVE")]
3053    CodeCOVE,
3054}
3055
3056impl SettlementMethod1Code1 {
3057    pub fn validate(&self) -> Result<(), ValidationError> {
3058        Ok(())
3059    }
3060}
3061
3062// SettlementTimeRequest21: Time by when the payment must be settled to avoid rejection.
3063#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3064pub struct SettlementTimeRequest21 {
3065    #[serde(rename = "CLSTm", skip_serializing_if = "Option::is_none")]
3066    pub cls_tm: Option<String>,
3067    #[serde(rename = "TillTm", skip_serializing_if = "Option::is_none")]
3068    pub till_tm: Option<String>,
3069    #[serde(rename = "FrTm", skip_serializing_if = "Option::is_none")]
3070    pub fr_tm: Option<String>,
3071    #[serde(rename = "RjctTm", skip_serializing_if = "Option::is_none")]
3072    pub rjct_tm: Option<String>,
3073}
3074
3075impl SettlementTimeRequest21 {
3076    pub fn validate(&self) -> Result<(), ValidationError> {
3077        if let Some(ref val) = self.cls_tm {
3078            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
3079            if !pattern.is_match(val) {
3080                return Err(ValidationError::new(
3081                    1005,
3082                    "cls_tm does not match the required pattern".to_string(),
3083                ));
3084            }
3085        }
3086        if let Some(ref val) = self.till_tm {
3087            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
3088            if !pattern.is_match(val) {
3089                return Err(ValidationError::new(
3090                    1005,
3091                    "till_tm does not match the required pattern".to_string(),
3092                ));
3093            }
3094        }
3095        if let Some(ref val) = self.fr_tm {
3096            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
3097            if !pattern.is_match(val) {
3098                return Err(ValidationError::new(
3099                    1005,
3100                    "fr_tm does not match the required pattern".to_string(),
3101                ));
3102            }
3103        }
3104        if let Some(ref val) = self.rjct_tm {
3105            let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
3106            if !pattern.is_match(val) {
3107                return Err(ValidationError::new(
3108                    1005,
3109                    "rjct_tm does not match the required pattern".to_string(),
3110                ));
3111            }
3112        }
3113        Ok(())
3114    }
3115}
3116
3117// StructuredRegulatoryReporting31: Additional details that cater for specific domestic regulatory requirements.
3118#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
3119pub struct StructuredRegulatoryReporting31 {
3120    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
3121    pub tp: Option<String>,
3122    #[serde(rename = "Dt", skip_serializing_if = "Option::is_none")]
3123    pub dt: Option<String>,
3124    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
3125    pub ctry: Option<String>,
3126    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
3127    pub cd: Option<String>,
3128    #[serde(rename = "Amt", skip_serializing_if = "Option::is_none")]
3129    pub amt: Option<CBPRAmount1>,
3130    #[serde(rename = "Inf", skip_serializing_if = "Option::is_none")]
3131    pub inf: Option<Vec<String>>,
3132}
3133
3134impl StructuredRegulatoryReporting31 {
3135    pub fn validate(&self) -> Result<(), ValidationError> {
3136        if let Some(ref val) = self.tp {
3137            if val.chars().count() < 1 {
3138                return Err(ValidationError::new(
3139                    1001,
3140                    "tp is shorter than the minimum length of 1".to_string(),
3141                ));
3142            }
3143            if val.chars().count() > 35 {
3144                return Err(ValidationError::new(
3145                    1002,
3146                    "tp exceeds the maximum length of 35".to_string(),
3147                ));
3148            }
3149            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
3150            if !pattern.is_match(val) {
3151                return Err(ValidationError::new(
3152                    1005,
3153                    "tp does not match the required pattern".to_string(),
3154                ));
3155            }
3156        }
3157        if let Some(ref val) = self.ctry {
3158            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
3159            if !pattern.is_match(val) {
3160                return Err(ValidationError::new(
3161                    1005,
3162                    "ctry does not match the required pattern".to_string(),
3163                ));
3164            }
3165        }
3166        if let Some(ref val) = self.cd {
3167            if val.chars().count() < 1 {
3168                return Err(ValidationError::new(
3169                    1001,
3170                    "cd is shorter than the minimum length of 1".to_string(),
3171                ));
3172            }
3173            if val.chars().count() > 10 {
3174                return Err(ValidationError::new(
3175                    1002,
3176                    "cd exceeds the maximum length of 10".to_string(),
3177                ));
3178            }
3179            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
3180            if !pattern.is_match(val) {
3181                return Err(ValidationError::new(
3182                    1005,
3183                    "cd does not match the required pattern".to_string(),
3184                ));
3185            }
3186        }
3187        if let Some(ref val) = self.amt {
3188            val.validate()?
3189        }
3190        if let Some(ref vec) = self.inf {
3191            for item in vec {
3192                if item.chars().count() < 1 {
3193                    return Err(ValidationError::new(
3194                        1001,
3195                        "inf is shorter than the minimum length of 1".to_string(),
3196                    ));
3197                }
3198                if item.chars().count() > 35 {
3199                    return Err(ValidationError::new(
3200                        1002,
3201                        "inf exceeds the maximum length of 35".to_string(),
3202                    ));
3203                }
3204                let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
3205                if !pattern.is_match(&item) {
3206                    return Err(ValidationError::new(
3207                        1005,
3208                        "inf does not match the required pattern".to_string(),
3209                    ));
3210                }
3211            }
3212        }
3213        Ok(())
3214    }
3215}