mx_message/document/
camt_106_001_02.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// BranchAndFinancialInstitutionIdentification81: 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 BranchAndFinancialInstitutionIdentification81 {
104    #[serde(rename = "FinInstnId")]
105    pub fin_instn_id: FinancialInstitutionIdentification231,
106}
107
108impl BranchAndFinancialInstitutionIdentification81 {
109    pub fn validate(&self) -> Result<(), ValidationError> {
110        self.fin_instn_id.validate()?;
111        Ok(())
112    }
113}
114
115// CBPRAmount: CBPR_Amount
116#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
117pub struct CBPRAmount {
118    #[serde(rename = "@Ccy")]
119    pub ccy: String,
120    #[serde(rename = "$value")]
121    pub value: f64,
122}
123
124impl CBPRAmount {
125    pub fn validate(&self) -> Result<(), ValidationError> {
126        Ok(())
127    }
128}
129
130// CashAccount401: Specifies an alternate assumed name for the identification of the account.
131#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
132pub struct CashAccount401 {
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 CashAccount401 {
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// ChargeType3Choice1: Charge type, in a coded form.
239#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
240pub struct ChargeType3Choice1 {
241    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
242    pub cd: Option<String>,
243}
244
245impl ChargeType3Choice1 {
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// Charges3Choice1: Charges broken down per payment transaction.
266#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
267pub struct Charges3Choice1 {
268    #[serde(rename = "PerTx", skip_serializing_if = "Option::is_none")]
269    pub per_tx: Option<ChargesPerTransaction31>,
270}
271
272impl Charges3Choice1 {
273    pub fn validate(&self) -> Result<(), ValidationError> {
274        if let Some(ref val) = self.per_tx {
275            val.validate()?
276        }
277        Ok(())
278    }
279}
280
281// ChargesBreakdown11: Specifies the type of charge.
282#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
283pub struct ChargesBreakdown11 {
284    #[serde(rename = "Amt")]
285    pub amt: CBPRAmount,
286    #[serde(rename = "CdtDbtInd")]
287    pub cdt_dbt_ind: CreditDebitCode1,
288    #[serde(rename = "Tp")]
289    pub tp: ChargeType3Choice1,
290}
291
292impl ChargesBreakdown11 {
293    pub fn validate(&self) -> Result<(), ValidationError> {
294        self.amt.validate()?;
295        self.cdt_dbt_ind.validate()?;
296        self.tp.validate()?;
297        Ok(())
298    }
299}
300
301// ChargesPaymentRequestV02: Provides information on the charges to be paid by the charge bearer(s) related to the processing of the underlying transaction.
302#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
303pub struct ChargesPaymentRequestV02 {
304    #[serde(rename = "GrpHdr")]
305    pub grp_hdr: GroupHeader1151,
306    #[serde(rename = "Chrgs")]
307    pub chrgs: Charges3Choice1,
308}
309
310impl ChargesPaymentRequestV02 {
311    pub fn validate(&self) -> Result<(), ValidationError> {
312        self.grp_hdr.validate()?;
313        self.chrgs.validate()?;
314        Ok(())
315    }
316}
317
318// ChargesPerTransaction31: Itemised charges record per transaction.
319#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
320pub struct ChargesPerTransaction31 {
321    #[serde(rename = "ChrgsId")]
322    pub chrgs_id: String,
323    #[serde(rename = "Rcrd")]
324    pub rcrd: ChargesPerTransactionRecord31,
325}
326
327impl ChargesPerTransaction31 {
328    pub fn validate(&self) -> Result<(), ValidationError> {
329        if self.chrgs_id.chars().count() < 1 {
330            return Err(ValidationError::new(
331                1001,
332                "chrgs_id is shorter than the minimum length of 1".to_string(),
333            ));
334        }
335        if self.chrgs_id.chars().count() > 16 {
336            return Err(ValidationError::new(
337                1002,
338                "chrgs_id exceeds the maximum length of 16".to_string(),
339            ));
340        }
341        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
342        if !pattern.is_match(&self.chrgs_id) {
343            return Err(ValidationError::new(
344                1005,
345                "chrgs_id does not match the required pattern".to_string(),
346            ));
347        }
348        self.rcrd.validate()?;
349        Ok(())
350    }
351}
352
353// ChargesPerTransactionRecord31: Further information related to the processing of the payment adjustment instruction that may need to be acted upon by the next agent.
354#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
355pub struct ChargesPerTransactionRecord31 {
356    #[serde(rename = "UndrlygTx")]
357    pub undrlyg_tx: TransactionReferences71,
358    #[serde(rename = "TtlChrgsPerRcrd")]
359    pub ttl_chrgs_per_rcrd: TotalCharges81,
360    #[serde(rename = "ChrgsBrkdwn")]
361    pub chrgs_brkdwn: Vec<ChargesBreakdown11>,
362    #[serde(rename = "DbtrAgt", skip_serializing_if = "Option::is_none")]
363    pub dbtr_agt: Option<BranchAndFinancialInstitutionIdentification81>,
364    #[serde(rename = "DbtrAgtAcct", skip_serializing_if = "Option::is_none")]
365    pub dbtr_agt_acct: Option<CashAccount401>,
366    #[serde(rename = "InstrForInstdAgt", skip_serializing_if = "Option::is_none")]
367    pub instr_for_instd_agt: Option<InstructionForInstructedAgent11>,
368}
369
370impl ChargesPerTransactionRecord31 {
371    pub fn validate(&self) -> Result<(), ValidationError> {
372        self.undrlyg_tx.validate()?;
373        self.ttl_chrgs_per_rcrd.validate()?;
374        for item in &self.chrgs_brkdwn {
375            item.validate()?
376        }
377        if let Some(ref val) = self.dbtr_agt {
378            val.validate()?
379        }
380        if let Some(ref val) = self.dbtr_agt_acct {
381            val.validate()?
382        }
383        if let Some(ref val) = self.instr_for_instd_agt {
384            val.validate()?
385        }
386        Ok(())
387    }
388}
389
390// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
391#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
392pub struct ClearingSystemIdentification2Choice1 {
393    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
394    pub cd: Option<String>,
395}
396
397impl ClearingSystemIdentification2Choice1 {
398    pub fn validate(&self) -> Result<(), ValidationError> {
399        if let Some(ref val) = self.cd {
400            if val.chars().count() < 1 {
401                return Err(ValidationError::new(
402                    1001,
403                    "cd is shorter than the minimum length of 1".to_string(),
404                ));
405            }
406            if val.chars().count() > 5 {
407                return Err(ValidationError::new(
408                    1002,
409                    "cd exceeds the maximum length of 5".to_string(),
410                ));
411            }
412        }
413        Ok(())
414    }
415}
416
417// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
418#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
419pub struct ClearingSystemMemberIdentification21 {
420    #[serde(rename = "ClrSysId")]
421    pub clr_sys_id: ClearingSystemIdentification2Choice1,
422    #[serde(rename = "MmbId")]
423    pub mmb_id: String,
424}
425
426impl ClearingSystemMemberIdentification21 {
427    pub fn validate(&self) -> Result<(), ValidationError> {
428        self.clr_sys_id.validate()?;
429        if self.mmb_id.chars().count() < 1 {
430            return Err(ValidationError::new(
431                1001,
432                "mmb_id is shorter than the minimum length of 1".to_string(),
433            ));
434        }
435        if self.mmb_id.chars().count() > 28 {
436            return Err(ValidationError::new(
437                1002,
438                "mmb_id exceeds the maximum length of 28".to_string(),
439            ));
440        }
441        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
442        if !pattern.is_match(&self.mmb_id) {
443            return Err(ValidationError::new(
444                1005,
445                "mmb_id does not match the required pattern".to_string(),
446            ));
447        }
448        Ok(())
449    }
450}
451
452// CreditDebitCode__1: Operation is a decrease.
453#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
454pub enum CreditDebitCode1 {
455    #[default]
456    #[serde(rename = "DBIT")]
457    CodeDBIT,
458}
459
460impl CreditDebitCode1 {
461    pub fn validate(&self) -> Result<(), ValidationError> {
462        Ok(())
463    }
464}
465
466// FinancialInstitutionIdentification231: Information that locates and identifies a specific address, as defined by postal services.
467#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
468pub struct FinancialInstitutionIdentification231 {
469    #[serde(rename = "BICFI", skip_serializing_if = "Option::is_none")]
470    pub bicfi: Option<String>,
471    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
472    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
473    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
474    pub lei: Option<String>,
475    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
476    pub nm: Option<String>,
477    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
478    pub pstl_adr: Option<PostalAddress271>,
479}
480
481impl FinancialInstitutionIdentification231 {
482    pub fn validate(&self) -> Result<(), ValidationError> {
483        if let Some(ref val) = self.bicfi {
484            let pattern =
485                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
486            if !pattern.is_match(val) {
487                return Err(ValidationError::new(
488                    1005,
489                    "bicfi does not match the required pattern".to_string(),
490                ));
491            }
492        }
493        if let Some(ref val) = self.clr_sys_mmb_id {
494            val.validate()?
495        }
496        if let Some(ref val) = self.lei {
497            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
498            if !pattern.is_match(val) {
499                return Err(ValidationError::new(
500                    1005,
501                    "lei does not match the required pattern".to_string(),
502                ));
503            }
504        }
505        if let Some(ref val) = self.nm {
506            if val.chars().count() < 1 {
507                return Err(ValidationError::new(
508                    1001,
509                    "nm is shorter than the minimum length of 1".to_string(),
510                ));
511            }
512            if val.chars().count() > 140 {
513                return Err(ValidationError::new(
514                    1002,
515                    "nm exceeds the maximum length of 140".to_string(),
516                ));
517            }
518            let pattern = Regex::new(
519                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
520            )
521            .unwrap();
522            if !pattern.is_match(val) {
523                return Err(ValidationError::new(
524                    1005,
525                    "nm does not match the required pattern".to_string(),
526                ));
527            }
528        }
529        if let Some(ref val) = self.pstl_adr {
530            val.validate()?
531        }
532        Ok(())
533    }
534}
535
536// GenericAccountIdentification11: Entity that assigns the identification.
537#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
538pub struct GenericAccountIdentification11 {
539    #[serde(rename = "Id")]
540    pub id: String,
541    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
542    pub schme_nm: Option<AccountSchemeName1Choice1>,
543    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
544    pub issr: Option<String>,
545}
546
547impl GenericAccountIdentification11 {
548    pub fn validate(&self) -> Result<(), ValidationError> {
549        if self.id.chars().count() < 1 {
550            return Err(ValidationError::new(
551                1001,
552                "id is shorter than the minimum length of 1".to_string(),
553            ));
554        }
555        if self.id.chars().count() > 34 {
556            return Err(ValidationError::new(
557                1002,
558                "id exceeds the maximum length of 34".to_string(),
559            ));
560        }
561        let pattern = Regex::new("([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]([0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ]*(/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+ ])?)*)").unwrap();
562        if !pattern.is_match(&self.id) {
563            return Err(ValidationError::new(
564                1005,
565                "id does not match the required pattern".to_string(),
566            ));
567        }
568        if let Some(ref val) = self.schme_nm {
569            val.validate()?
570        }
571        if let Some(ref val) = self.issr {
572            if val.chars().count() < 1 {
573                return Err(ValidationError::new(
574                    1001,
575                    "issr is shorter than the minimum length of 1".to_string(),
576                ));
577            }
578            if val.chars().count() > 35 {
579                return Err(ValidationError::new(
580                    1002,
581                    "issr exceeds the maximum length of 35".to_string(),
582                ));
583            }
584            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
585            if !pattern.is_match(val) {
586                return Err(ValidationError::new(
587                    1005,
588                    "issr does not match the required pattern".to_string(),
589                ));
590            }
591        }
592        Ok(())
593    }
594}
595
596// GroupHeader1151: Account of the agent that services the charges account.
597#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
598pub struct GroupHeader1151 {
599    #[serde(rename = "MsgId")]
600    pub msg_id: String,
601    #[serde(rename = "CreDtTm")]
602    pub cre_dt_tm: String,
603    #[serde(rename = "ChrgsRqstr")]
604    pub chrgs_rqstr: BranchAndFinancialInstitutionIdentification81,
605    #[serde(rename = "ChrgsAcctAgt", skip_serializing_if = "Option::is_none")]
606    pub chrgs_acct_agt: Option<BranchAndFinancialInstitutionIdentification81>,
607    #[serde(rename = "ChrgsAcctAgtAcct", skip_serializing_if = "Option::is_none")]
608    pub chrgs_acct_agt_acct: Option<CashAccount401>,
609}
610
611impl GroupHeader1151 {
612    pub fn validate(&self) -> Result<(), ValidationError> {
613        if self.msg_id.chars().count() < 1 {
614            return Err(ValidationError::new(
615                1001,
616                "msg_id is shorter than the minimum length of 1".to_string(),
617            ));
618        }
619        if self.msg_id.chars().count() > 35 {
620            return Err(ValidationError::new(
621                1002,
622                "msg_id exceeds the maximum length of 35".to_string(),
623            ));
624        }
625        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
626        if !pattern.is_match(&self.msg_id) {
627            return Err(ValidationError::new(
628                1005,
629                "msg_id does not match the required pattern".to_string(),
630            ));
631        }
632        let pattern = Regex::new(".*(\\+|-)((0[0-9])|(1[0-4])):[0-5][0-9]").unwrap();
633        if !pattern.is_match(&self.cre_dt_tm) {
634            return Err(ValidationError::new(
635                1005,
636                "cre_dt_tm does not match the required pattern".to_string(),
637            ));
638        }
639        self.chrgs_rqstr.validate()?;
640        if let Some(ref val) = self.chrgs_acct_agt {
641            val.validate()?
642        }
643        if let Some(ref val) = self.chrgs_acct_agt_acct {
644            val.validate()?
645        }
646        Ok(())
647    }
648}
649
650// InstructionForInstructedAgent11: Further information complementing the coded instruction or instruction to the instructed agent that is bilaterally agreed or specific to a user community.
651#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
652pub struct InstructionForInstructedAgent11 {
653    #[serde(rename = "Cd")]
654    pub cd: String,
655    #[serde(rename = "InstrInf", skip_serializing_if = "Option::is_none")]
656    pub instr_inf: Option<String>,
657}
658
659impl InstructionForInstructedAgent11 {
660    pub fn validate(&self) -> Result<(), ValidationError> {
661        if self.cd.chars().count() < 1 {
662            return Err(ValidationError::new(
663                1001,
664                "cd is shorter than the minimum length of 1".to_string(),
665            ));
666        }
667        if self.cd.chars().count() > 4 {
668            return Err(ValidationError::new(
669                1002,
670                "cd exceeds the maximum length of 4".to_string(),
671            ));
672        }
673        if let Some(ref val) = self.instr_inf {
674            if val.chars().count() < 1 {
675                return Err(ValidationError::new(
676                    1001,
677                    "instr_inf is shorter than the minimum length of 1".to_string(),
678                ));
679            }
680            if val.chars().count() > 140 {
681                return Err(ValidationError::new(
682                    1002,
683                    "instr_inf exceeds the maximum length of 140".to_string(),
684                ));
685            }
686            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
687            if !pattern.is_match(val) {
688                return Err(ValidationError::new(
689                    1005,
690                    "instr_inf does not match the required pattern".to_string(),
691                ));
692            }
693        }
694        Ok(())
695    }
696}
697
698// PostalAddress271: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
699#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
700pub struct PostalAddress271 {
701    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
702    pub dept: Option<String>,
703    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
704    pub sub_dept: Option<String>,
705    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
706    pub strt_nm: Option<String>,
707    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
708    pub bldg_nb: Option<String>,
709    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
710    pub bldg_nm: Option<String>,
711    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
712    pub flr: Option<String>,
713    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
714    pub pst_bx: Option<String>,
715    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
716    pub room: Option<String>,
717    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
718    pub pst_cd: Option<String>,
719    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
720    pub twn_nm: Option<String>,
721    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
722    pub twn_lctn_nm: Option<String>,
723    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
724    pub dstrct_nm: Option<String>,
725    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
726    pub ctry_sub_dvsn: Option<String>,
727    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
728    pub ctry: Option<String>,
729    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
730    pub adr_line: Option<Vec<String>>,
731}
732
733impl PostalAddress271 {
734    pub fn validate(&self) -> Result<(), ValidationError> {
735        if let Some(ref val) = self.dept {
736            if val.chars().count() < 1 {
737                return Err(ValidationError::new(
738                    1001,
739                    "dept is shorter than the minimum length of 1".to_string(),
740                ));
741            }
742            if val.chars().count() > 70 {
743                return Err(ValidationError::new(
744                    1002,
745                    "dept exceeds the maximum length of 70".to_string(),
746                ));
747            }
748            let pattern = Regex::new(
749                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
750            )
751            .unwrap();
752            if !pattern.is_match(val) {
753                return Err(ValidationError::new(
754                    1005,
755                    "dept does not match the required pattern".to_string(),
756                ));
757            }
758        }
759        if let Some(ref val) = self.sub_dept {
760            if val.chars().count() < 1 {
761                return Err(ValidationError::new(
762                    1001,
763                    "sub_dept is shorter than the minimum length of 1".to_string(),
764                ));
765            }
766            if val.chars().count() > 70 {
767                return Err(ValidationError::new(
768                    1002,
769                    "sub_dept exceeds the maximum length of 70".to_string(),
770                ));
771            }
772            let pattern = Regex::new(
773                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
774            )
775            .unwrap();
776            if !pattern.is_match(val) {
777                return Err(ValidationError::new(
778                    1005,
779                    "sub_dept does not match the required pattern".to_string(),
780                ));
781            }
782        }
783        if let Some(ref val) = self.strt_nm {
784            if val.chars().count() < 1 {
785                return Err(ValidationError::new(
786                    1001,
787                    "strt_nm is shorter than the minimum length of 1".to_string(),
788                ));
789            }
790            if val.chars().count() > 70 {
791                return Err(ValidationError::new(
792                    1002,
793                    "strt_nm exceeds the maximum length of 70".to_string(),
794                ));
795            }
796            let pattern = Regex::new(
797                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
798            )
799            .unwrap();
800            if !pattern.is_match(val) {
801                return Err(ValidationError::new(
802                    1005,
803                    "strt_nm does not match the required pattern".to_string(),
804                ));
805            }
806        }
807        if let Some(ref val) = self.bldg_nb {
808            if val.chars().count() < 1 {
809                return Err(ValidationError::new(
810                    1001,
811                    "bldg_nb is shorter than the minimum length of 1".to_string(),
812                ));
813            }
814            if val.chars().count() > 16 {
815                return Err(ValidationError::new(
816                    1002,
817                    "bldg_nb exceeds the maximum length of 16".to_string(),
818                ));
819            }
820            let pattern = Regex::new(
821                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
822            )
823            .unwrap();
824            if !pattern.is_match(val) {
825                return Err(ValidationError::new(
826                    1005,
827                    "bldg_nb does not match the required pattern".to_string(),
828                ));
829            }
830        }
831        if let Some(ref val) = self.bldg_nm {
832            if val.chars().count() < 1 {
833                return Err(ValidationError::new(
834                    1001,
835                    "bldg_nm is shorter than the minimum length of 1".to_string(),
836                ));
837            }
838            if val.chars().count() > 35 {
839                return Err(ValidationError::new(
840                    1002,
841                    "bldg_nm exceeds the maximum length of 35".to_string(),
842                ));
843            }
844            let pattern = Regex::new(
845                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
846            )
847            .unwrap();
848            if !pattern.is_match(val) {
849                return Err(ValidationError::new(
850                    1005,
851                    "bldg_nm does not match the required pattern".to_string(),
852                ));
853            }
854        }
855        if let Some(ref val) = self.flr {
856            if val.chars().count() < 1 {
857                return Err(ValidationError::new(
858                    1001,
859                    "flr is shorter than the minimum length of 1".to_string(),
860                ));
861            }
862            if val.chars().count() > 70 {
863                return Err(ValidationError::new(
864                    1002,
865                    "flr exceeds the maximum length of 70".to_string(),
866                ));
867            }
868            let pattern = Regex::new(
869                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
870            )
871            .unwrap();
872            if !pattern.is_match(val) {
873                return Err(ValidationError::new(
874                    1005,
875                    "flr does not match the required pattern".to_string(),
876                ));
877            }
878        }
879        if let Some(ref val) = self.pst_bx {
880            if val.chars().count() < 1 {
881                return Err(ValidationError::new(
882                    1001,
883                    "pst_bx is shorter than the minimum length of 1".to_string(),
884                ));
885            }
886            if val.chars().count() > 16 {
887                return Err(ValidationError::new(
888                    1002,
889                    "pst_bx exceeds the maximum length of 16".to_string(),
890                ));
891            }
892            let pattern = Regex::new(
893                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
894            )
895            .unwrap();
896            if !pattern.is_match(val) {
897                return Err(ValidationError::new(
898                    1005,
899                    "pst_bx does not match the required pattern".to_string(),
900                ));
901            }
902        }
903        if let Some(ref val) = self.room {
904            if val.chars().count() < 1 {
905                return Err(ValidationError::new(
906                    1001,
907                    "room is shorter than the minimum length of 1".to_string(),
908                ));
909            }
910            if val.chars().count() > 70 {
911                return Err(ValidationError::new(
912                    1002,
913                    "room exceeds the maximum length of 70".to_string(),
914                ));
915            }
916            let pattern = Regex::new(
917                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
918            )
919            .unwrap();
920            if !pattern.is_match(val) {
921                return Err(ValidationError::new(
922                    1005,
923                    "room does not match the required pattern".to_string(),
924                ));
925            }
926        }
927        if let Some(ref val) = self.pst_cd {
928            if val.chars().count() < 1 {
929                return Err(ValidationError::new(
930                    1001,
931                    "pst_cd is shorter than the minimum length of 1".to_string(),
932                ));
933            }
934            if val.chars().count() > 16 {
935                return Err(ValidationError::new(
936                    1002,
937                    "pst_cd exceeds the maximum length of 16".to_string(),
938                ));
939            }
940            let pattern = Regex::new(
941                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
942            )
943            .unwrap();
944            if !pattern.is_match(val) {
945                return Err(ValidationError::new(
946                    1005,
947                    "pst_cd does not match the required pattern".to_string(),
948                ));
949            }
950        }
951        if let Some(ref val) = self.twn_nm {
952            if val.chars().count() < 1 {
953                return Err(ValidationError::new(
954                    1001,
955                    "twn_nm is shorter than the minimum length of 1".to_string(),
956                ));
957            }
958            if val.chars().count() > 35 {
959                return Err(ValidationError::new(
960                    1002,
961                    "twn_nm exceeds the maximum length of 35".to_string(),
962                ));
963            }
964            let pattern = Regex::new(
965                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
966            )
967            .unwrap();
968            if !pattern.is_match(val) {
969                return Err(ValidationError::new(
970                    1005,
971                    "twn_nm does not match the required pattern".to_string(),
972                ));
973            }
974        }
975        if let Some(ref val) = self.twn_lctn_nm {
976            if val.chars().count() < 1 {
977                return Err(ValidationError::new(
978                    1001,
979                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
980                ));
981            }
982            if val.chars().count() > 35 {
983                return Err(ValidationError::new(
984                    1002,
985                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
986                ));
987            }
988            let pattern = Regex::new(
989                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
990            )
991            .unwrap();
992            if !pattern.is_match(val) {
993                return Err(ValidationError::new(
994                    1005,
995                    "twn_lctn_nm does not match the required pattern".to_string(),
996                ));
997            }
998        }
999        if let Some(ref val) = self.dstrct_nm {
1000            if val.chars().count() < 1 {
1001                return Err(ValidationError::new(
1002                    1001,
1003                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
1004                ));
1005            }
1006            if val.chars().count() > 35 {
1007                return Err(ValidationError::new(
1008                    1002,
1009                    "dstrct_nm exceeds the maximum length of 35".to_string(),
1010                ));
1011            }
1012            let pattern = Regex::new(
1013                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1014            )
1015            .unwrap();
1016            if !pattern.is_match(val) {
1017                return Err(ValidationError::new(
1018                    1005,
1019                    "dstrct_nm does not match the required pattern".to_string(),
1020                ));
1021            }
1022        }
1023        if let Some(ref val) = self.ctry_sub_dvsn {
1024            if val.chars().count() < 1 {
1025                return Err(ValidationError::new(
1026                    1001,
1027                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
1028                ));
1029            }
1030            if val.chars().count() > 35 {
1031                return Err(ValidationError::new(
1032                    1002,
1033                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
1034                ));
1035            }
1036            let pattern = Regex::new(
1037                "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1038            )
1039            .unwrap();
1040            if !pattern.is_match(val) {
1041                return Err(ValidationError::new(
1042                    1005,
1043                    "ctry_sub_dvsn does not match the required pattern".to_string(),
1044                ));
1045            }
1046        }
1047        if let Some(ref val) = self.ctry {
1048            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
1049            if !pattern.is_match(val) {
1050                return Err(ValidationError::new(
1051                    1005,
1052                    "ctry does not match the required pattern".to_string(),
1053                ));
1054            }
1055        }
1056        if let Some(ref vec) = self.adr_line {
1057            for item in vec {
1058                if item.chars().count() < 1 {
1059                    return Err(ValidationError::new(
1060                        1001,
1061                        "adr_line is shorter than the minimum length of 1".to_string(),
1062                    ));
1063                }
1064                if item.chars().count() > 70 {
1065                    return Err(ValidationError::new(
1066                        1002,
1067                        "adr_line exceeds the maximum length of 70".to_string(),
1068                    ));
1069                }
1070                let pattern = Regex::new(
1071                    "[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+",
1072                )
1073                .unwrap();
1074                if !pattern.is_match(&item) {
1075                    return Err(ValidationError::new(
1076                        1005,
1077                        "adr_line does not match the required pattern".to_string(),
1078                    ));
1079                }
1080            }
1081        }
1082        Ok(())
1083    }
1084}
1085
1086// ProxyAccountIdentification11: Identification used to indicate the account identification under another specified name.
1087#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1088pub struct ProxyAccountIdentification11 {
1089    #[serde(rename = "Tp", skip_serializing_if = "Option::is_none")]
1090    pub tp: Option<ProxyAccountType1Choice1>,
1091    #[serde(rename = "Id")]
1092    pub id: String,
1093}
1094
1095impl ProxyAccountIdentification11 {
1096    pub fn validate(&self) -> Result<(), ValidationError> {
1097        if let Some(ref val) = self.tp {
1098            val.validate()?
1099        }
1100        if self.id.chars().count() < 1 {
1101            return Err(ValidationError::new(
1102                1001,
1103                "id is shorter than the minimum length of 1".to_string(),
1104            ));
1105        }
1106        if self.id.chars().count() > 320 {
1107            return Err(ValidationError::new(
1108                1002,
1109                "id exceeds the maximum length of 320".to_string(),
1110            ));
1111        }
1112        let pattern =
1113            Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ !#$%&\\*=^_`\\{\\|\\}~\";<>@\\[\\\\\\]]+")
1114                .unwrap();
1115        if !pattern.is_match(&self.id) {
1116            return Err(ValidationError::new(
1117                1005,
1118                "id does not match the required pattern".to_string(),
1119            ));
1120        }
1121        Ok(())
1122    }
1123}
1124
1125// ProxyAccountType1Choice1: Name of the identification scheme, in a free text form.
1126#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1127pub struct ProxyAccountType1Choice1 {
1128    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1129    pub cd: Option<String>,
1130    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
1131    pub prtry: Option<String>,
1132}
1133
1134impl ProxyAccountType1Choice1 {
1135    pub fn validate(&self) -> Result<(), ValidationError> {
1136        if let Some(ref val) = self.cd {
1137            if val.chars().count() < 1 {
1138                return Err(ValidationError::new(
1139                    1001,
1140                    "cd is shorter than the minimum length of 1".to_string(),
1141                ));
1142            }
1143            if val.chars().count() > 4 {
1144                return Err(ValidationError::new(
1145                    1002,
1146                    "cd exceeds the maximum length of 4".to_string(),
1147                ));
1148            }
1149        }
1150        if let Some(ref val) = self.prtry {
1151            if val.chars().count() < 1 {
1152                return Err(ValidationError::new(
1153                    1001,
1154                    "prtry is shorter than the minimum length of 1".to_string(),
1155                ));
1156            }
1157            if val.chars().count() > 35 {
1158                return Err(ValidationError::new(
1159                    1002,
1160                    "prtry exceeds the maximum length of 35".to_string(),
1161                ));
1162            }
1163            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1164            if !pattern.is_match(val) {
1165                return Err(ValidationError::new(
1166                    1005,
1167                    "prtry does not match the required pattern".to_string(),
1168                ));
1169            }
1170        }
1171        Ok(())
1172    }
1173}
1174
1175// TotalCharges81: Indicates whether the total charges amount is a credit or a debit amount.
1176// Usage: A zero amount is considered to be a credit.
1177#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1178pub struct TotalCharges81 {
1179    #[serde(rename = "NbOfChrgsBrkdwnItms")]
1180    pub nb_of_chrgs_brkdwn_itms: String,
1181    #[serde(rename = "TtlChrgsAmt")]
1182    pub ttl_chrgs_amt: CBPRAmount,
1183    #[serde(rename = "CdtDbtInd")]
1184    pub cdt_dbt_ind: CreditDebitCode1,
1185}
1186
1187impl TotalCharges81 {
1188    pub fn validate(&self) -> Result<(), ValidationError> {
1189        let pattern = Regex::new("[0-9]{1,15}").unwrap();
1190        if !pattern.is_match(&self.nb_of_chrgs_brkdwn_itms) {
1191            return Err(ValidationError::new(
1192                1005,
1193                "nb_of_chrgs_brkdwn_itms does not match the required pattern".to_string(),
1194            ));
1195        }
1196        self.ttl_chrgs_amt.validate()?;
1197        self.cdt_dbt_ind.validate()?;
1198        Ok(())
1199    }
1200}
1201
1202// TransactionReferences71: Identification of the securities transaction assigned by the processor of the instruction other than the securities account owner, the securities account servicer and the market infrastructure.
1203#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1204pub struct TransactionReferences71 {
1205    #[serde(rename = "MsgId", skip_serializing_if = "Option::is_none")]
1206    pub msg_id: Option<String>,
1207    #[serde(rename = "MsgNmId")]
1208    pub msg_nm_id: String,
1209    #[serde(rename = "AcctSvcrRef", skip_serializing_if = "Option::is_none")]
1210    pub acct_svcr_ref: Option<String>,
1211    #[serde(rename = "PmtInfId", skip_serializing_if = "Option::is_none")]
1212    pub pmt_inf_id: Option<String>,
1213    #[serde(rename = "InstrId", skip_serializing_if = "Option::is_none")]
1214    pub instr_id: Option<String>,
1215    #[serde(rename = "EndToEndId", skip_serializing_if = "Option::is_none")]
1216    pub end_to_end_id: Option<String>,
1217    #[serde(rename = "UETR", skip_serializing_if = "Option::is_none")]
1218    pub uetr: Option<String>,
1219    #[serde(rename = "TxId", skip_serializing_if = "Option::is_none")]
1220    pub tx_id: Option<String>,
1221    #[serde(rename = "MndtId", skip_serializing_if = "Option::is_none")]
1222    pub mndt_id: Option<String>,
1223    #[serde(rename = "ChqNb", skip_serializing_if = "Option::is_none")]
1224    pub chq_nb: Option<String>,
1225    #[serde(rename = "AcctOwnrTxId", skip_serializing_if = "Option::is_none")]
1226    pub acct_ownr_tx_id: Option<String>,
1227    #[serde(rename = "AcctSvcrTxId", skip_serializing_if = "Option::is_none")]
1228    pub acct_svcr_tx_id: Option<String>,
1229    #[serde(rename = "PrcgId", skip_serializing_if = "Option::is_none")]
1230    pub prcg_id: Option<String>,
1231}
1232
1233impl TransactionReferences71 {
1234    pub fn validate(&self) -> Result<(), ValidationError> {
1235        if let Some(ref val) = self.msg_id {
1236            if val.chars().count() < 1 {
1237                return Err(ValidationError::new(
1238                    1001,
1239                    "msg_id is shorter than the minimum length of 1".to_string(),
1240                ));
1241            }
1242            if val.chars().count() > 35 {
1243                return Err(ValidationError::new(
1244                    1002,
1245                    "msg_id exceeds the maximum length of 35".to_string(),
1246                ));
1247            }
1248            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1249            if !pattern.is_match(val) {
1250                return Err(ValidationError::new(
1251                    1005,
1252                    "msg_id does not match the required pattern".to_string(),
1253                ));
1254            }
1255        }
1256        if self.msg_nm_id.chars().count() < 1 {
1257            return Err(ValidationError::new(
1258                1001,
1259                "msg_nm_id is shorter than the minimum length of 1".to_string(),
1260            ));
1261        }
1262        if self.msg_nm_id.chars().count() > 35 {
1263            return Err(ValidationError::new(
1264                1002,
1265                "msg_nm_id exceeds the maximum length of 35".to_string(),
1266            ));
1267        }
1268        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1269        if !pattern.is_match(&self.msg_nm_id) {
1270            return Err(ValidationError::new(
1271                1005,
1272                "msg_nm_id does not match the required pattern".to_string(),
1273            ));
1274        }
1275        if let Some(ref val) = self.acct_svcr_ref {
1276            if val.chars().count() < 1 {
1277                return Err(ValidationError::new(
1278                    1001,
1279                    "acct_svcr_ref is shorter than the minimum length of 1".to_string(),
1280                ));
1281            }
1282            if val.chars().count() > 35 {
1283                return Err(ValidationError::new(
1284                    1002,
1285                    "acct_svcr_ref exceeds the maximum length of 35".to_string(),
1286                ));
1287            }
1288            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1289            if !pattern.is_match(val) {
1290                return Err(ValidationError::new(
1291                    1005,
1292                    "acct_svcr_ref does not match the required pattern".to_string(),
1293                ));
1294            }
1295        }
1296        if let Some(ref val) = self.pmt_inf_id {
1297            if val.chars().count() < 1 {
1298                return Err(ValidationError::new(
1299                    1001,
1300                    "pmt_inf_id is shorter than the minimum length of 1".to_string(),
1301                ));
1302            }
1303            if val.chars().count() > 35 {
1304                return Err(ValidationError::new(
1305                    1002,
1306                    "pmt_inf_id exceeds the maximum length of 35".to_string(),
1307                ));
1308            }
1309            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1310            if !pattern.is_match(val) {
1311                return Err(ValidationError::new(
1312                    1005,
1313                    "pmt_inf_id does not match the required pattern".to_string(),
1314                ));
1315            }
1316        }
1317        if let Some(ref val) = self.instr_id {
1318            if val.chars().count() < 1 {
1319                return Err(ValidationError::new(
1320                    1001,
1321                    "instr_id is shorter than the minimum length of 1".to_string(),
1322                ));
1323            }
1324            if val.chars().count() > 16 {
1325                return Err(ValidationError::new(
1326                    1002,
1327                    "instr_id exceeds the maximum length of 16".to_string(),
1328                ));
1329            }
1330            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1331            if !pattern.is_match(val) {
1332                return Err(ValidationError::new(
1333                    1005,
1334                    "instr_id does not match the required pattern".to_string(),
1335                ));
1336            }
1337        }
1338        if let Some(ref val) = self.end_to_end_id {
1339            if val.chars().count() < 1 {
1340                return Err(ValidationError::new(
1341                    1001,
1342                    "end_to_end_id is shorter than the minimum length of 1".to_string(),
1343                ));
1344            }
1345            if val.chars().count() > 35 {
1346                return Err(ValidationError::new(
1347                    1002,
1348                    "end_to_end_id exceeds the maximum length of 35".to_string(),
1349                ));
1350            }
1351            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1352            if !pattern.is_match(val) {
1353                return Err(ValidationError::new(
1354                    1005,
1355                    "end_to_end_id does not match the required pattern".to_string(),
1356                ));
1357            }
1358        }
1359        if let Some(ref val) = self.uetr {
1360            let pattern =
1361                Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
1362                    .unwrap();
1363            if !pattern.is_match(val) {
1364                return Err(ValidationError::new(
1365                    1005,
1366                    "uetr does not match the required pattern".to_string(),
1367                ));
1368            }
1369        }
1370        if let Some(ref val) = self.tx_id {
1371            if val.chars().count() < 1 {
1372                return Err(ValidationError::new(
1373                    1001,
1374                    "tx_id is shorter than the minimum length of 1".to_string(),
1375                ));
1376            }
1377            if val.chars().count() > 35 {
1378                return Err(ValidationError::new(
1379                    1002,
1380                    "tx_id exceeds the maximum length of 35".to_string(),
1381                ));
1382            }
1383            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1384            if !pattern.is_match(val) {
1385                return Err(ValidationError::new(
1386                    1005,
1387                    "tx_id does not match the required pattern".to_string(),
1388                ));
1389            }
1390        }
1391        if let Some(ref val) = self.mndt_id {
1392            if val.chars().count() < 1 {
1393                return Err(ValidationError::new(
1394                    1001,
1395                    "mndt_id is shorter than the minimum length of 1".to_string(),
1396                ));
1397            }
1398            if val.chars().count() > 35 {
1399                return Err(ValidationError::new(
1400                    1002,
1401                    "mndt_id exceeds the maximum length of 35".to_string(),
1402                ));
1403            }
1404            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1405            if !pattern.is_match(val) {
1406                return Err(ValidationError::new(
1407                    1005,
1408                    "mndt_id does not match the required pattern".to_string(),
1409                ));
1410            }
1411        }
1412        if let Some(ref val) = self.chq_nb {
1413            if val.chars().count() < 1 {
1414                return Err(ValidationError::new(
1415                    1001,
1416                    "chq_nb is shorter than the minimum length of 1".to_string(),
1417                ));
1418            }
1419            if val.chars().count() > 35 {
1420                return Err(ValidationError::new(
1421                    1002,
1422                    "chq_nb exceeds the maximum length of 35".to_string(),
1423                ));
1424            }
1425            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1426            if !pattern.is_match(val) {
1427                return Err(ValidationError::new(
1428                    1005,
1429                    "chq_nb does not match the required pattern".to_string(),
1430                ));
1431            }
1432        }
1433        if let Some(ref val) = self.acct_ownr_tx_id {
1434            if val.chars().count() < 1 {
1435                return Err(ValidationError::new(
1436                    1001,
1437                    "acct_ownr_tx_id is shorter than the minimum length of 1".to_string(),
1438                ));
1439            }
1440            if val.chars().count() > 35 {
1441                return Err(ValidationError::new(
1442                    1002,
1443                    "acct_ownr_tx_id exceeds the maximum length of 35".to_string(),
1444                ));
1445            }
1446            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1447            if !pattern.is_match(val) {
1448                return Err(ValidationError::new(
1449                    1005,
1450                    "acct_ownr_tx_id does not match the required pattern".to_string(),
1451                ));
1452            }
1453        }
1454        if let Some(ref val) = self.acct_svcr_tx_id {
1455            if val.chars().count() < 1 {
1456                return Err(ValidationError::new(
1457                    1001,
1458                    "acct_svcr_tx_id is shorter than the minimum length of 1".to_string(),
1459                ));
1460            }
1461            if val.chars().count() > 35 {
1462                return Err(ValidationError::new(
1463                    1002,
1464                    "acct_svcr_tx_id exceeds the maximum length of 35".to_string(),
1465                ));
1466            }
1467            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1468            if !pattern.is_match(val) {
1469                return Err(ValidationError::new(
1470                    1005,
1471                    "acct_svcr_tx_id does not match the required pattern".to_string(),
1472                ));
1473            }
1474        }
1475        if let Some(ref val) = self.prcg_id {
1476            if val.chars().count() < 1 {
1477                return Err(ValidationError::new(
1478                    1001,
1479                    "prcg_id is shorter than the minimum length of 1".to_string(),
1480                ));
1481            }
1482            if val.chars().count() > 35 {
1483                return Err(ValidationError::new(
1484                    1002,
1485                    "prcg_id exceeds the maximum length of 35".to_string(),
1486                ));
1487            }
1488            let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
1489            if !pattern.is_match(val) {
1490                return Err(ValidationError::new(
1491                    1005,
1492                    "prcg_id does not match the required pattern".to_string(),
1493                ));
1494            }
1495        }
1496        Ok(())
1497    }
1498}