1use crate::camt_029_001_09::ResolutionOfInvestigationV09;
21use crate::camt_056_001_08::FIToFIPaymentCancellationRequestV08;
22use crate::camt_057_001_06::NotificationToReceiveV06;
23use crate::common::ValidationError;
24use crate::pacs_008_001_08::FIToFICustomerCreditTransferV08;
25use crate::pacs_009_001_08::FinancialInstitutionCreditTransferV08;
26use serde::{Deserialize, Serialize};
27
28#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
30pub enum Document {
31 #[serde(rename = "FIToFICstmrCdtTrf")]
33 FIToFICustomerCreditTransferV08(Box<FIToFICustomerCreditTransferV08>),
34
35 #[serde(rename = "FinInstnCdtTrf")]
37 FinancialInstitutionCreditTransferV08(Box<FinancialInstitutionCreditTransferV08>),
38
39 #[serde(rename = "RsltnOfInvstgtn")]
41 ResolutionOfInvestigationV09(Box<ResolutionOfInvestigationV09>),
42
43 #[serde(rename = "FIToFIPmtCxlReq")]
45 FIToFIPaymentCancellationRequestV08(Box<FIToFIPaymentCancellationRequestV08>),
46
47 #[serde(rename = "NtfctnToRcv")]
49 NotificationToReceiveV06(Box<NotificationToReceiveV06>),
50
51 #[default]
53 UNKNOWN,
54}
55
56impl Document {
57 pub fn validate(&self) -> Result<(), ValidationError> {
59 match self {
60 Document::FIToFICustomerCreditTransferV08(value) => value.validate(),
61 Document::FinancialInstitutionCreditTransferV08(value) => value.validate(),
62 Document::ResolutionOfInvestigationV09(value) => value.validate(),
63 Document::FIToFIPaymentCancellationRequestV08(value) => value.validate(),
64 Document::NotificationToReceiveV06(value) => value.validate(),
65 Document::UNKNOWN => {
66 Err(ValidationError::new(
68 9999,
69 "Unknown document type".to_string(),
70 ))
71 }
72 }
73 }
74
75 pub fn message_type(&self) -> &'static str {
77 match self {
78 Document::FIToFICustomerCreditTransferV08(_) => "pacs.008.001.08",
79 Document::FinancialInstitutionCreditTransferV08(_) => "pacs.009.001.08",
80 Document::ResolutionOfInvestigationV09(_) => "camt.029.001.09",
81 Document::FIToFIPaymentCancellationRequestV08(_) => "camt.056.001.08",
82 Document::NotificationToReceiveV06(_) => "camt.057.001.06",
83 Document::UNKNOWN => "unknown",
84 }
85 }
86
87 pub fn is_cbpr_plus_compliant(&self) -> bool {
89 match self {
90 Document::UNKNOWN => false,
91 _ => true, }
93 }
94}