mx_message/document/
pain_002_001_10.rs

1// Plasmatic MX Message Parsing Library
2// https://github.com/GoPlasmatic/MXMessage
3//
4// Copyright (c) 2025 Plasmatic
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// You may obtain a copy of this library at
18// https://github.com/GoPlasmatic/MXMessage
19
20use crate::error::*;
21use regex::Regex;
22use serde::{Deserialize, Serialize};
23
24// BranchAndFinancialInstitutionIdentification61: Unique and unambiguous identification of a financial institution, as assigned under an internationally recognised or proprietary identification scheme.
25#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
26pub struct BranchAndFinancialInstitutionIdentification61 {
27    #[serde(rename = "FinInstnId")]
28    pub fin_instn_id: FinancialInstitutionIdentification181,
29}
30
31impl BranchAndFinancialInstitutionIdentification61 {
32    pub fn validate(&self) -> Result<(), ValidationError> {
33        self.fin_instn_id.validate()?;
34        Ok(())
35    }
36}
37
38// ClearingSystemIdentification2Choice1: Identification of a clearing system, in a coded form as published in an external list.
39#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
40pub struct ClearingSystemIdentification2Choice1 {
41    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
42    pub cd: Option<String>,
43}
44
45impl ClearingSystemIdentification2Choice1 {
46    pub fn validate(&self) -> Result<(), ValidationError> {
47        if let Some(ref val) = self.cd {
48            if val.chars().count() < 1 {
49                return Err(ValidationError::new(
50                    1001,
51                    "cd is shorter than the minimum length of 1".to_string(),
52                ));
53            }
54            if val.chars().count() > 5 {
55                return Err(ValidationError::new(
56                    1002,
57                    "cd exceeds the maximum length of 5".to_string(),
58                ));
59            }
60        }
61        Ok(())
62    }
63}
64
65// ClearingSystemMemberIdentification21: Identification of a member of a clearing system.
66#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
67pub struct ClearingSystemMemberIdentification21 {
68    #[serde(rename = "ClrSysId")]
69    pub clr_sys_id: ClearingSystemIdentification2Choice1,
70    #[serde(rename = "MmbId")]
71    pub mmb_id: String,
72}
73
74impl ClearingSystemMemberIdentification21 {
75    pub fn validate(&self) -> Result<(), ValidationError> {
76        self.clr_sys_id.validate()?;
77        if self.mmb_id.chars().count() < 1 {
78            return Err(ValidationError::new(
79                1001,
80                "mmb_id is shorter than the minimum length of 1".to_string(),
81            ));
82        }
83        if self.mmb_id.chars().count() > 35 {
84            return Err(ValidationError::new(
85                1002,
86                "mmb_id exceeds the maximum length of 35".to_string(),
87            ));
88        }
89        Ok(())
90    }
91}
92
93// CustomerPaymentStatusReportV10: Information concerning the original payment information, to which the status report message refers.
94#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
95pub struct CustomerPaymentStatusReportV10 {
96    #[serde(rename = "GrpHdr")]
97    pub grp_hdr: GroupHeader861,
98    #[serde(rename = "OrgnlGrpInfAndSts")]
99    pub orgnl_grp_inf_and_sts: OriginalGroupHeader171,
100    #[serde(rename = "OrgnlPmtInfAndSts")]
101    pub orgnl_pmt_inf_and_sts: OriginalPaymentInstruction321,
102}
103
104impl CustomerPaymentStatusReportV10 {
105    pub fn validate(&self) -> Result<(), ValidationError> {
106        self.grp_hdr.validate()?;
107        self.orgnl_grp_inf_and_sts.validate()?;
108        self.orgnl_pmt_inf_and_sts.validate()?;
109        Ok(())
110    }
111}
112
113// DateAndPlaceOfBirth1: Country where a person was born.
114#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
115pub struct DateAndPlaceOfBirth1 {
116    #[serde(rename = "BirthDt")]
117    pub birth_dt: String,
118    #[serde(rename = "PrvcOfBirth", skip_serializing_if = "Option::is_none")]
119    pub prvc_of_birth: Option<String>,
120    #[serde(rename = "CityOfBirth")]
121    pub city_of_birth: String,
122    #[serde(rename = "CtryOfBirth")]
123    pub ctry_of_birth: String,
124}
125
126impl DateAndPlaceOfBirth1 {
127    pub fn validate(&self) -> Result<(), ValidationError> {
128        if let Some(ref val) = self.prvc_of_birth {
129            if val.chars().count() < 1 {
130                return Err(ValidationError::new(
131                    1001,
132                    "prvc_of_birth is shorter than the minimum length of 1".to_string(),
133                ));
134            }
135            if val.chars().count() > 35 {
136                return Err(ValidationError::new(
137                    1002,
138                    "prvc_of_birth exceeds the maximum length of 35".to_string(),
139                ));
140            }
141        }
142        if self.city_of_birth.chars().count() < 1 {
143            return Err(ValidationError::new(
144                1001,
145                "city_of_birth is shorter than the minimum length of 1".to_string(),
146            ));
147        }
148        if self.city_of_birth.chars().count() > 35 {
149            return Err(ValidationError::new(
150                1002,
151                "city_of_birth exceeds the maximum length of 35".to_string(),
152            ));
153        }
154        let pattern = Regex::new("[A-Z]{2,2}").unwrap();
155        if !pattern.is_match(&self.ctry_of_birth) {
156            return Err(ValidationError::new(
157                1005,
158                "ctry_of_birth does not match the required pattern".to_string(),
159            ));
160        }
161        Ok(())
162    }
163}
164
165// FinancialInstitutionIdentification181: Legal entity identifier of the financial institution.
166#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
167pub struct FinancialInstitutionIdentification181 {
168    #[serde(rename = "BICFI")]
169    pub bicfi: String,
170    #[serde(rename = "ClrSysMmbId", skip_serializing_if = "Option::is_none")]
171    pub clr_sys_mmb_id: Option<ClearingSystemMemberIdentification21>,
172    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
173    pub lei: Option<String>,
174}
175
176impl FinancialInstitutionIdentification181 {
177    pub fn validate(&self) -> Result<(), ValidationError> {
178        let pattern =
179            Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
180        if !pattern.is_match(&self.bicfi) {
181            return Err(ValidationError::new(
182                1005,
183                "bicfi does not match the required pattern".to_string(),
184            ));
185        }
186        if let Some(ref val) = self.clr_sys_mmb_id {
187            val.validate()?
188        }
189        if let Some(ref val) = self.lei {
190            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
191            if !pattern.is_match(val) {
192                return Err(ValidationError::new(
193                    1005,
194                    "lei does not match the required pattern".to_string(),
195                ));
196            }
197        }
198        Ok(())
199    }
200}
201
202// GenericOrganisationIdentification1: Entity that assigns the identification.
203#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
204pub struct GenericOrganisationIdentification1 {
205    #[serde(rename = "Id")]
206    pub id: String,
207    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
208    pub schme_nm: Option<OrganisationIdentificationSchemeName1Choice>,
209    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
210    pub issr: Option<String>,
211}
212
213impl GenericOrganisationIdentification1 {
214    pub fn validate(&self) -> Result<(), ValidationError> {
215        if self.id.chars().count() < 1 {
216            return Err(ValidationError::new(
217                1001,
218                "id is shorter than the minimum length of 1".to_string(),
219            ));
220        }
221        if self.id.chars().count() > 35 {
222            return Err(ValidationError::new(
223                1002,
224                "id exceeds the maximum length of 35".to_string(),
225            ));
226        }
227        if let Some(ref val) = self.schme_nm {
228            val.validate()?
229        }
230        if let Some(ref val) = self.issr {
231            if val.chars().count() < 1 {
232                return Err(ValidationError::new(
233                    1001,
234                    "issr is shorter than the minimum length of 1".to_string(),
235                ));
236            }
237            if val.chars().count() > 35 {
238                return Err(ValidationError::new(
239                    1002,
240                    "issr exceeds the maximum length of 35".to_string(),
241                ));
242            }
243        }
244        Ok(())
245    }
246}
247
248// GenericPersonIdentification1: Entity that assigns the identification.
249#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
250pub struct GenericPersonIdentification1 {
251    #[serde(rename = "Id")]
252    pub id: String,
253    #[serde(rename = "SchmeNm", skip_serializing_if = "Option::is_none")]
254    pub schme_nm: Option<PersonIdentificationSchemeName1Choice>,
255    #[serde(rename = "Issr", skip_serializing_if = "Option::is_none")]
256    pub issr: Option<String>,
257}
258
259impl GenericPersonIdentification1 {
260    pub fn validate(&self) -> Result<(), ValidationError> {
261        if self.id.chars().count() < 1 {
262            return Err(ValidationError::new(
263                1001,
264                "id is shorter than the minimum length of 1".to_string(),
265            ));
266        }
267        if self.id.chars().count() > 35 {
268            return Err(ValidationError::new(
269                1002,
270                "id exceeds the maximum length of 35".to_string(),
271            ));
272        }
273        if let Some(ref val) = self.schme_nm {
274            val.validate()?
275        }
276        if let Some(ref val) = self.issr {
277            if val.chars().count() < 1 {
278                return Err(ValidationError::new(
279                    1001,
280                    "issr is shorter than the minimum length of 1".to_string(),
281                ));
282            }
283            if val.chars().count() > 35 {
284                return Err(ValidationError::new(
285                    1002,
286                    "issr exceeds the maximum length of 35".to_string(),
287                ));
288            }
289        }
290        Ok(())
291    }
292}
293
294// GroupHeader861: Financial institution that receives the instruction from the initiating party and forwards it to the next agent in the payment chain.
295#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
296pub struct GroupHeader861 {
297    #[serde(rename = "MsgId")]
298    pub msg_id: String,
299    #[serde(rename = "CreDtTm")]
300    pub cre_dt_tm: String,
301    #[serde(rename = "InitgPty")]
302    pub initg_pty: PartyIdentification1351,
303    #[serde(rename = "FwdgAgt", skip_serializing_if = "Option::is_none")]
304    pub fwdg_agt: Option<BranchAndFinancialInstitutionIdentification61>,
305}
306
307impl GroupHeader861 {
308    pub fn validate(&self) -> Result<(), ValidationError> {
309        if self.msg_id.chars().count() < 1 {
310            return Err(ValidationError::new(
311                1001,
312                "msg_id is shorter than the minimum length of 1".to_string(),
313            ));
314        }
315        if self.msg_id.chars().count() > 35 {
316            return Err(ValidationError::new(
317                1002,
318                "msg_id exceeds the maximum length of 35".to_string(),
319            ));
320        }
321        let pattern = Regex::new("[0-9a-zA-Z/\\-\\?:\\(\\)\\.,'\\+ ]+").unwrap();
322        if !pattern.is_match(&self.msg_id) {
323            return Err(ValidationError::new(
324                1005,
325                "msg_id does not match the required pattern".to_string(),
326            ));
327        }
328        self.initg_pty.validate()?;
329        if let Some(ref val) = self.fwdg_agt {
330            val.validate()?
331        }
332        Ok(())
333    }
334}
335
336// OrganisationIdentification291: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
337#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
338pub struct OrganisationIdentification291 {
339    #[serde(rename = "AnyBIC")]
340    pub any_bic: String,
341    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
342    pub lei: Option<String>,
343    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
344    pub othr: Option<Vec<GenericOrganisationIdentification1>>,
345}
346
347impl OrganisationIdentification291 {
348    pub fn validate(&self) -> Result<(), ValidationError> {
349        let pattern =
350            Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
351        if !pattern.is_match(&self.any_bic) {
352            return Err(ValidationError::new(
353                1005,
354                "any_bic does not match the required pattern".to_string(),
355            ));
356        }
357        if let Some(ref val) = self.lei {
358            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
359            if !pattern.is_match(val) {
360                return Err(ValidationError::new(
361                    1005,
362                    "lei does not match the required pattern".to_string(),
363                ));
364            }
365        }
366        if let Some(ref vec) = self.othr {
367            for item in vec {
368                item.validate()?
369            }
370        }
371        Ok(())
372    }
373}
374
375// OrganisationIdentification292: Unique identification of an organisation, as assigned by an institution, using an identification scheme.
376#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
377pub struct OrganisationIdentification292 {
378    #[serde(rename = "AnyBIC", skip_serializing_if = "Option::is_none")]
379    pub any_bic: Option<String>,
380    #[serde(rename = "LEI", skip_serializing_if = "Option::is_none")]
381    pub lei: Option<String>,
382    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
383    pub othr: Option<Vec<GenericOrganisationIdentification1>>,
384}
385
386impl OrganisationIdentification292 {
387    pub fn validate(&self) -> Result<(), ValidationError> {
388        if let Some(ref val) = self.any_bic {
389            let pattern =
390                Regex::new("[A-Z0-9]{4,4}[A-Z]{2,2}[A-Z0-9]{2,2}([A-Z0-9]{3,3}){0,1}").unwrap();
391            if !pattern.is_match(val) {
392                return Err(ValidationError::new(
393                    1005,
394                    "any_bic does not match the required pattern".to_string(),
395                ));
396            }
397        }
398        if let Some(ref val) = self.lei {
399            let pattern = Regex::new("[A-Z0-9]{18,18}[0-9]{2,2}").unwrap();
400            if !pattern.is_match(val) {
401                return Err(ValidationError::new(
402                    1005,
403                    "lei does not match the required pattern".to_string(),
404                ));
405            }
406        }
407        if let Some(ref vec) = self.othr {
408            for item in vec {
409                item.validate()?
410            }
411        }
412        Ok(())
413    }
414}
415
416// OrganisationIdentificationSchemeName1Choice: Name of the identification scheme, in a free text form.
417#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
418pub struct OrganisationIdentificationSchemeName1Choice {
419    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
420    pub cd: Option<String>,
421    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
422    pub prtry: Option<String>,
423}
424
425impl OrganisationIdentificationSchemeName1Choice {
426    pub fn validate(&self) -> Result<(), ValidationError> {
427        if let Some(ref val) = self.cd {
428            if val.chars().count() < 1 {
429                return Err(ValidationError::new(
430                    1001,
431                    "cd is shorter than the minimum length of 1".to_string(),
432                ));
433            }
434            if val.chars().count() > 4 {
435                return Err(ValidationError::new(
436                    1002,
437                    "cd exceeds the maximum length of 4".to_string(),
438                ));
439            }
440        }
441        if let Some(ref val) = self.prtry {
442            if val.chars().count() < 1 {
443                return Err(ValidationError::new(
444                    1001,
445                    "prtry is shorter than the minimum length of 1".to_string(),
446                ));
447            }
448            if val.chars().count() > 35 {
449                return Err(ValidationError::new(
450                    1002,
451                    "prtry exceeds the maximum length of 35".to_string(),
452                ));
453            }
454        }
455        Ok(())
456    }
457}
458
459// OriginalGroupHeader171: Date and time at which the original message was created.
460#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
461pub struct OriginalGroupHeader171 {
462    #[serde(rename = "OrgnlMsgId")]
463    pub orgnl_msg_id: String,
464    #[serde(rename = "OrgnlMsgNmId")]
465    pub orgnl_msg_nm_id: String,
466    #[serde(rename = "OrgnlCreDtTm", skip_serializing_if = "Option::is_none")]
467    pub orgnl_cre_dt_tm: Option<String>,
468}
469
470impl OriginalGroupHeader171 {
471    pub fn validate(&self) -> Result<(), ValidationError> {
472        if self.orgnl_msg_id.chars().count() < 1 {
473            return Err(ValidationError::new(
474                1001,
475                "orgnl_msg_id is shorter than the minimum length of 1".to_string(),
476            ));
477        }
478        if self.orgnl_msg_id.chars().count() > 35 {
479            return Err(ValidationError::new(
480                1002,
481                "orgnl_msg_id exceeds the maximum length of 35".to_string(),
482            ));
483        }
484        if self.orgnl_msg_nm_id.chars().count() < 1 {
485            return Err(ValidationError::new(
486                1001,
487                "orgnl_msg_nm_id is shorter than the minimum length of 1".to_string(),
488            ));
489        }
490        if self.orgnl_msg_nm_id.chars().count() > 35 {
491            return Err(ValidationError::new(
492                1002,
493                "orgnl_msg_nm_id exceeds the maximum length of 35".to_string(),
494            ));
495        }
496        Ok(())
497    }
498}
499
500// OriginalPaymentInstruction321: Provides information on the original transactions to which the status report message refers.
501#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
502pub struct OriginalPaymentInstruction321 {
503    #[serde(rename = "OrgnlPmtInfId")]
504    pub orgnl_pmt_inf_id: String,
505    #[serde(rename = "TxInfAndSts")]
506    pub tx_inf_and_sts: PaymentTransaction1051,
507}
508
509impl OriginalPaymentInstruction321 {
510    pub fn validate(&self) -> Result<(), ValidationError> {
511        if self.orgnl_pmt_inf_id.chars().count() < 1 {
512            return Err(ValidationError::new(
513                1001,
514                "orgnl_pmt_inf_id is shorter than the minimum length of 1".to_string(),
515            ));
516        }
517        if self.orgnl_pmt_inf_id.chars().count() > 35 {
518            return Err(ValidationError::new(
519                1002,
520                "orgnl_pmt_inf_id exceeds the maximum length of 35".to_string(),
521            ));
522        }
523        self.tx_inf_and_sts.validate()?;
524        Ok(())
525    }
526}
527
528// Party38Choice1: Unique and unambiguous way to identify an organisation.
529#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
530pub struct Party38Choice1 {
531    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
532    pub org_id: Option<OrganisationIdentification291>,
533}
534
535impl Party38Choice1 {
536    pub fn validate(&self) -> Result<(), ValidationError> {
537        if let Some(ref val) = self.org_id {
538            val.validate()?
539        }
540        Ok(())
541    }
542}
543
544// Party38Choice2: Unique and unambiguous identification of a person, for example a passport.
545#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
546pub struct Party38Choice2 {
547    #[serde(rename = "OrgId", skip_serializing_if = "Option::is_none")]
548    pub org_id: Option<OrganisationIdentification292>,
549    #[serde(rename = "PrvtId", skip_serializing_if = "Option::is_none")]
550    pub prvt_id: Option<PersonIdentification131>,
551}
552
553impl Party38Choice2 {
554    pub fn validate(&self) -> Result<(), ValidationError> {
555        if let Some(ref val) = self.org_id {
556            val.validate()?
557        }
558        if let Some(ref val) = self.prvt_id {
559            val.validate()?
560        }
561        Ok(())
562    }
563}
564
565// PartyIdentification1351: Unique and unambiguous identification of a party.
566#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
567pub struct PartyIdentification1351 {
568    #[serde(rename = "Id")]
569    pub id: Party38Choice1,
570}
571
572impl PartyIdentification1351 {
573    pub fn validate(&self) -> Result<(), ValidationError> {
574        self.id.validate()?;
575        Ok(())
576    }
577}
578
579// 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.
580#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
581pub struct PartyIdentification1352 {
582    #[serde(rename = "Nm", skip_serializing_if = "Option::is_none")]
583    pub nm: Option<String>,
584    #[serde(rename = "PstlAdr", skip_serializing_if = "Option::is_none")]
585    pub pstl_adr: Option<PostalAddress241>,
586    #[serde(rename = "Id", skip_serializing_if = "Option::is_none")]
587    pub id: Option<Party38Choice2>,
588    #[serde(rename = "CtryOfRes", skip_serializing_if = "Option::is_none")]
589    pub ctry_of_res: Option<String>,
590}
591
592impl PartyIdentification1352 {
593    pub fn validate(&self) -> Result<(), ValidationError> {
594        if let Some(ref val) = self.nm {
595            if val.chars().count() < 1 {
596                return Err(ValidationError::new(
597                    1001,
598                    "nm is shorter than the minimum length of 1".to_string(),
599                ));
600            }
601            if val.chars().count() > 140 {
602                return Err(ValidationError::new(
603                    1002,
604                    "nm exceeds the maximum length of 140".to_string(),
605                ));
606            }
607        }
608        if let Some(ref val) = self.pstl_adr {
609            val.validate()?
610        }
611        if let Some(ref val) = self.id {
612            val.validate()?
613        }
614        if let Some(ref val) = self.ctry_of_res {
615            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
616            if !pattern.is_match(val) {
617                return Err(ValidationError::new(
618                    1005,
619                    "ctry_of_res does not match the required pattern".to_string(),
620                ));
621            }
622        }
623        Ok(())
624    }
625}
626
627// PaymentTransaction1051: Provides detailed information on the status reason.
628#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
629pub struct PaymentTransaction1051 {
630    #[serde(rename = "OrgnlInstrId", skip_serializing_if = "Option::is_none")]
631    pub orgnl_instr_id: Option<String>,
632    #[serde(rename = "OrgnlEndToEndId")]
633    pub orgnl_end_to_end_id: String,
634    #[serde(rename = "OrgnlUETR")]
635    pub orgnl_uetr: String,
636    #[serde(rename = "TxSts")]
637    pub tx_sts: String,
638    #[serde(rename = "StsRsnInf", skip_serializing_if = "Option::is_none")]
639    pub sts_rsn_inf: Option<StatusReasonInformation121>,
640}
641
642impl PaymentTransaction1051 {
643    pub fn validate(&self) -> Result<(), ValidationError> {
644        if let Some(ref val) = self.orgnl_instr_id {
645            if val.chars().count() < 1 {
646                return Err(ValidationError::new(
647                    1001,
648                    "orgnl_instr_id is shorter than the minimum length of 1".to_string(),
649                ));
650            }
651            if val.chars().count() > 35 {
652                return Err(ValidationError::new(
653                    1002,
654                    "orgnl_instr_id exceeds the maximum length of 35".to_string(),
655                ));
656            }
657        }
658        if self.orgnl_end_to_end_id.chars().count() < 1 {
659            return Err(ValidationError::new(
660                1001,
661                "orgnl_end_to_end_id is shorter than the minimum length of 1".to_string(),
662            ));
663        }
664        if self.orgnl_end_to_end_id.chars().count() > 35 {
665            return Err(ValidationError::new(
666                1002,
667                "orgnl_end_to_end_id exceeds the maximum length of 35".to_string(),
668            ));
669        }
670        let pattern =
671            Regex::new("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}")
672                .unwrap();
673        if !pattern.is_match(&self.orgnl_uetr) {
674            return Err(ValidationError::new(
675                1005,
676                "orgnl_uetr does not match the required pattern".to_string(),
677            ));
678        }
679        if self.tx_sts.chars().count() < 1 {
680            return Err(ValidationError::new(
681                1001,
682                "tx_sts is shorter than the minimum length of 1".to_string(),
683            ));
684        }
685        if self.tx_sts.chars().count() > 4 {
686            return Err(ValidationError::new(
687                1002,
688                "tx_sts exceeds the maximum length of 4".to_string(),
689            ));
690        }
691        if let Some(ref val) = self.sts_rsn_inf {
692            val.validate()?
693        }
694        Ok(())
695    }
696}
697
698// PersonIdentification131: Unique identification of a person, as assigned by an institution, using an identification scheme.
699#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
700pub struct PersonIdentification131 {
701    #[serde(rename = "DtAndPlcOfBirth", skip_serializing_if = "Option::is_none")]
702    pub dt_and_plc_of_birth: Option<DateAndPlaceOfBirth1>,
703    #[serde(rename = "Othr", skip_serializing_if = "Option::is_none")]
704    pub othr: Option<Vec<GenericPersonIdentification1>>,
705}
706
707impl PersonIdentification131 {
708    pub fn validate(&self) -> Result<(), ValidationError> {
709        if let Some(ref val) = self.dt_and_plc_of_birth {
710            val.validate()?
711        }
712        if let Some(ref vec) = self.othr {
713            for item in vec {
714                item.validate()?
715            }
716        }
717        Ok(())
718    }
719}
720
721// PersonIdentificationSchemeName1Choice: Name of the identification scheme, in a free text form.
722#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
723pub struct PersonIdentificationSchemeName1Choice {
724    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
725    pub cd: Option<String>,
726    #[serde(rename = "Prtry", skip_serializing_if = "Option::is_none")]
727    pub prtry: Option<String>,
728}
729
730impl PersonIdentificationSchemeName1Choice {
731    pub fn validate(&self) -> Result<(), ValidationError> {
732        if let Some(ref val) = self.cd {
733            if val.chars().count() < 1 {
734                return Err(ValidationError::new(
735                    1001,
736                    "cd is shorter than the minimum length of 1".to_string(),
737                ));
738            }
739            if val.chars().count() > 4 {
740                return Err(ValidationError::new(
741                    1002,
742                    "cd exceeds the maximum length of 4".to_string(),
743                ));
744            }
745        }
746        if let Some(ref val) = self.prtry {
747            if val.chars().count() < 1 {
748                return Err(ValidationError::new(
749                    1001,
750                    "prtry is shorter than the minimum length of 1".to_string(),
751                ));
752            }
753            if val.chars().count() > 35 {
754                return Err(ValidationError::new(
755                    1002,
756                    "prtry exceeds the maximum length of 35".to_string(),
757                ));
758            }
759        }
760        Ok(())
761    }
762}
763
764// PostalAddress241: Information that locates and identifies a specific address, as defined by postal services, presented in free format text.
765#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
766pub struct PostalAddress241 {
767    #[serde(rename = "Dept", skip_serializing_if = "Option::is_none")]
768    pub dept: Option<String>,
769    #[serde(rename = "SubDept", skip_serializing_if = "Option::is_none")]
770    pub sub_dept: Option<String>,
771    #[serde(rename = "StrtNm", skip_serializing_if = "Option::is_none")]
772    pub strt_nm: Option<String>,
773    #[serde(rename = "BldgNb", skip_serializing_if = "Option::is_none")]
774    pub bldg_nb: Option<String>,
775    #[serde(rename = "BldgNm", skip_serializing_if = "Option::is_none")]
776    pub bldg_nm: Option<String>,
777    #[serde(rename = "Flr", skip_serializing_if = "Option::is_none")]
778    pub flr: Option<String>,
779    #[serde(rename = "PstBx", skip_serializing_if = "Option::is_none")]
780    pub pst_bx: Option<String>,
781    #[serde(rename = "Room", skip_serializing_if = "Option::is_none")]
782    pub room: Option<String>,
783    #[serde(rename = "PstCd", skip_serializing_if = "Option::is_none")]
784    pub pst_cd: Option<String>,
785    #[serde(rename = "TwnNm", skip_serializing_if = "Option::is_none")]
786    pub twn_nm: Option<String>,
787    #[serde(rename = "TwnLctnNm", skip_serializing_if = "Option::is_none")]
788    pub twn_lctn_nm: Option<String>,
789    #[serde(rename = "DstrctNm", skip_serializing_if = "Option::is_none")]
790    pub dstrct_nm: Option<String>,
791    #[serde(rename = "CtrySubDvsn", skip_serializing_if = "Option::is_none")]
792    pub ctry_sub_dvsn: Option<String>,
793    #[serde(rename = "Ctry", skip_serializing_if = "Option::is_none")]
794    pub ctry: Option<String>,
795    #[serde(rename = "AdrLine", skip_serializing_if = "Option::is_none")]
796    pub adr_line: Option<Vec<String>>,
797}
798
799impl PostalAddress241 {
800    pub fn validate(&self) -> Result<(), ValidationError> {
801        if let Some(ref val) = self.dept {
802            if val.chars().count() < 1 {
803                return Err(ValidationError::new(
804                    1001,
805                    "dept is shorter than the minimum length of 1".to_string(),
806                ));
807            }
808            if val.chars().count() > 70 {
809                return Err(ValidationError::new(
810                    1002,
811                    "dept exceeds the maximum length of 70".to_string(),
812                ));
813            }
814        }
815        if let Some(ref val) = self.sub_dept {
816            if val.chars().count() < 1 {
817                return Err(ValidationError::new(
818                    1001,
819                    "sub_dept is shorter than the minimum length of 1".to_string(),
820                ));
821            }
822            if val.chars().count() > 70 {
823                return Err(ValidationError::new(
824                    1002,
825                    "sub_dept exceeds the maximum length of 70".to_string(),
826                ));
827            }
828        }
829        if let Some(ref val) = self.strt_nm {
830            if val.chars().count() < 1 {
831                return Err(ValidationError::new(
832                    1001,
833                    "strt_nm is shorter than the minimum length of 1".to_string(),
834                ));
835            }
836            if val.chars().count() > 70 {
837                return Err(ValidationError::new(
838                    1002,
839                    "strt_nm exceeds the maximum length of 70".to_string(),
840                ));
841            }
842        }
843        if let Some(ref val) = self.bldg_nb {
844            if val.chars().count() < 1 {
845                return Err(ValidationError::new(
846                    1001,
847                    "bldg_nb is shorter than the minimum length of 1".to_string(),
848                ));
849            }
850            if val.chars().count() > 16 {
851                return Err(ValidationError::new(
852                    1002,
853                    "bldg_nb exceeds the maximum length of 16".to_string(),
854                ));
855            }
856        }
857        if let Some(ref val) = self.bldg_nm {
858            if val.chars().count() < 1 {
859                return Err(ValidationError::new(
860                    1001,
861                    "bldg_nm is shorter than the minimum length of 1".to_string(),
862                ));
863            }
864            if val.chars().count() > 35 {
865                return Err(ValidationError::new(
866                    1002,
867                    "bldg_nm exceeds the maximum length of 35".to_string(),
868                ));
869            }
870        }
871        if let Some(ref val) = self.flr {
872            if val.chars().count() < 1 {
873                return Err(ValidationError::new(
874                    1001,
875                    "flr is shorter than the minimum length of 1".to_string(),
876                ));
877            }
878            if val.chars().count() > 70 {
879                return Err(ValidationError::new(
880                    1002,
881                    "flr exceeds the maximum length of 70".to_string(),
882                ));
883            }
884        }
885        if let Some(ref val) = self.pst_bx {
886            if val.chars().count() < 1 {
887                return Err(ValidationError::new(
888                    1001,
889                    "pst_bx is shorter than the minimum length of 1".to_string(),
890                ));
891            }
892            if val.chars().count() > 16 {
893                return Err(ValidationError::new(
894                    1002,
895                    "pst_bx exceeds the maximum length of 16".to_string(),
896                ));
897            }
898        }
899        if let Some(ref val) = self.room {
900            if val.chars().count() < 1 {
901                return Err(ValidationError::new(
902                    1001,
903                    "room is shorter than the minimum length of 1".to_string(),
904                ));
905            }
906            if val.chars().count() > 70 {
907                return Err(ValidationError::new(
908                    1002,
909                    "room exceeds the maximum length of 70".to_string(),
910                ));
911            }
912        }
913        if let Some(ref val) = self.pst_cd {
914            if val.chars().count() < 1 {
915                return Err(ValidationError::new(
916                    1001,
917                    "pst_cd is shorter than the minimum length of 1".to_string(),
918                ));
919            }
920            if val.chars().count() > 16 {
921                return Err(ValidationError::new(
922                    1002,
923                    "pst_cd exceeds the maximum length of 16".to_string(),
924                ));
925            }
926        }
927        if let Some(ref val) = self.twn_nm {
928            if val.chars().count() < 1 {
929                return Err(ValidationError::new(
930                    1001,
931                    "twn_nm is shorter than the minimum length of 1".to_string(),
932                ));
933            }
934            if val.chars().count() > 35 {
935                return Err(ValidationError::new(
936                    1002,
937                    "twn_nm exceeds the maximum length of 35".to_string(),
938                ));
939            }
940        }
941        if let Some(ref val) = self.twn_lctn_nm {
942            if val.chars().count() < 1 {
943                return Err(ValidationError::new(
944                    1001,
945                    "twn_lctn_nm is shorter than the minimum length of 1".to_string(),
946                ));
947            }
948            if val.chars().count() > 35 {
949                return Err(ValidationError::new(
950                    1002,
951                    "twn_lctn_nm exceeds the maximum length of 35".to_string(),
952                ));
953            }
954        }
955        if let Some(ref val) = self.dstrct_nm {
956            if val.chars().count() < 1 {
957                return Err(ValidationError::new(
958                    1001,
959                    "dstrct_nm is shorter than the minimum length of 1".to_string(),
960                ));
961            }
962            if val.chars().count() > 35 {
963                return Err(ValidationError::new(
964                    1002,
965                    "dstrct_nm exceeds the maximum length of 35".to_string(),
966                ));
967            }
968        }
969        if let Some(ref val) = self.ctry_sub_dvsn {
970            if val.chars().count() < 1 {
971                return Err(ValidationError::new(
972                    1001,
973                    "ctry_sub_dvsn is shorter than the minimum length of 1".to_string(),
974                ));
975            }
976            if val.chars().count() > 35 {
977                return Err(ValidationError::new(
978                    1002,
979                    "ctry_sub_dvsn exceeds the maximum length of 35".to_string(),
980                ));
981            }
982        }
983        if let Some(ref val) = self.ctry {
984            let pattern = Regex::new("[A-Z]{2,2}").unwrap();
985            if !pattern.is_match(val) {
986                return Err(ValidationError::new(
987                    1005,
988                    "ctry does not match the required pattern".to_string(),
989                ));
990            }
991        }
992        if let Some(ref vec) = self.adr_line {
993            for item in vec {
994                if item.chars().count() < 1 {
995                    return Err(ValidationError::new(
996                        1001,
997                        "adr_line is shorter than the minimum length of 1".to_string(),
998                    ));
999                }
1000                if item.chars().count() > 70 {
1001                    return Err(ValidationError::new(
1002                        1002,
1003                        "adr_line exceeds the maximum length of 70".to_string(),
1004                    ));
1005                }
1006            }
1007        }
1008        Ok(())
1009    }
1010}
1011
1012// StatusReason6Choice1: Reason for the status, as published in an external reason code list.
1013#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1014pub struct StatusReason6Choice1 {
1015    #[serde(rename = "Cd", skip_serializing_if = "Option::is_none")]
1016    pub cd: Option<String>,
1017}
1018
1019impl StatusReason6Choice1 {
1020    pub fn validate(&self) -> Result<(), ValidationError> {
1021        if let Some(ref val) = self.cd {
1022            if val.chars().count() < 1 {
1023                return Err(ValidationError::new(
1024                    1001,
1025                    "cd is shorter than the minimum length of 1".to_string(),
1026                ));
1027            }
1028            if val.chars().count() > 4 {
1029                return Err(ValidationError::new(
1030                    1002,
1031                    "cd exceeds the maximum length of 4".to_string(),
1032                ));
1033            }
1034        }
1035        Ok(())
1036    }
1037}
1038
1039// StatusReasonInformation121: Further details on the status reason.
1040//
1041// Usage: Additional information can be used for several purposes such as the reporting of repaired information.
1042#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
1043pub struct StatusReasonInformation121 {
1044    #[serde(rename = "Orgtr", skip_serializing_if = "Option::is_none")]
1045    pub orgtr: Option<PartyIdentification1352>,
1046    #[serde(rename = "Rsn", skip_serializing_if = "Option::is_none")]
1047    pub rsn: Option<StatusReason6Choice1>,
1048    #[serde(rename = "AddtlInf", skip_serializing_if = "Option::is_none")]
1049    pub addtl_inf: Option<Vec<String>>,
1050}
1051
1052impl StatusReasonInformation121 {
1053    pub fn validate(&self) -> Result<(), ValidationError> {
1054        if let Some(ref val) = self.orgtr {
1055            val.validate()?
1056        }
1057        if let Some(ref val) = self.rsn {
1058            val.validate()?
1059        }
1060        if let Some(ref vec) = self.addtl_inf {
1061            for item in vec {
1062                if item.chars().count() < 1 {
1063                    return Err(ValidationError::new(
1064                        1001,
1065                        "addtl_inf is shorter than the minimum length of 1".to_string(),
1066                    ));
1067                }
1068                if item.chars().count() > 105 {
1069                    return Err(ValidationError::new(
1070                        1002,
1071                        "addtl_inf exceeds the maximum length of 105".to_string(),
1072                    ));
1073                }
1074            }
1075        }
1076        Ok(())
1077    }
1078}