rust_iso20022 0.1.1

ISO 20022 message definitions and external code sets for Rust, generated from the official XSD schemas.
// @generated by src/bin/codegen.rs from the ISO 20022 XSD schema. Do not edit.
#![allow(clippy::all)]
#![allow(non_snake_case, non_camel_case_types, dead_code, unused_imports)]
// yaserde_derive 0.7 emits trait impls inside nested choice submodules, which
// trips the `non_local_definitions` lint on recent rustc. The generated code is
// correct; silence the lint here.
#![allow(non_local_definitions)]
use std::str::FromStr;
use crate::validate::Validate;
use yaserde_derive::{YaDeserialize, YaSerialize};

// pub type Document = Document;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Debug, Clone, YaSerialize, YaDeserialize)]#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]

pub enum BaselineStatus2Code {
    #[yaserde(rename = "COMP")]
    #[cfg_attr(feature = "serde", serde(rename = "COMP"))]
    Comp,
    #[yaserde(rename = "CLSD")]
    #[cfg_attr(feature = "serde", serde(rename = "CLSD"))]
    Clsd,
    #[yaserde(rename = "ACTV")]
    #[cfg_attr(feature = "serde", serde(rename = "ACTV"))]
    Actv,
    __Unknown__(String),
}

impl Default for BaselineStatus2Code {
    fn default() -> BaselineStatus2Code {
        Self::__Unknown__("No valid variants".into())
    }
}

impl Validate for BaselineStatus2Code {}



#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct Document {
    #[yaserde(rename = "StsChngReq")]
    #[cfg_attr(feature = "serde", serde(rename = "StsChngReq"))]
    pub sts_chng_req: StatusChangeRequestV02,
}

impl Validate for Document {}


#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug)]
pub struct IsodateTime (pub String);
crate::simple_type!(IsodateTime);

impl Validate for IsodateTime {}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug)]
pub struct Max140Text (pub String);
crate::simple_type!(Max140Text);

impl Validate for Max140Text {
    fn validate(&self) -> Result<(), String> { 
        #[allow(clippy::len_zero)]
        if self.0.len() < 1 {
            return Err(format!("MinLength validation error. \nExpected: 0 length >= 1 \nActual: 0 length == {}", self.0.len()));
        }
        if self.0.len() > 140 {
            return Err(format!("MaxLength validation error. \nExpected: 0 length <= 140 \nActual: 0 length == {}", self.0.len()));
        }
        Ok(())
    }
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug)]
pub struct Max35Text (pub String);
crate::simple_type!(Max35Text);

impl Validate for Max35Text {
    fn validate(&self) -> Result<(), String> { 
        #[allow(clippy::len_zero)]
        if self.0.len() < 1 {
            return Err(format!("MinLength validation error. \nExpected: 0 length >= 1 \nActual: 0 length == {}", self.0.len()));
        }
        if self.0.len() > 35 {
            return Err(format!("MaxLength validation error. \nExpected: 0 length <= 35 \nActual: 0 length == {}", self.0.len()));
        }
        Ok(())
    }
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct MessageIdentification1 {
    #[yaserde(rename = "Id")]
    #[cfg_attr(feature = "serde", serde(rename = "Id"))]
    pub id: Max35Text,

    #[yaserde(rename = "CreDtTm")]
    #[cfg_attr(feature = "serde", serde(rename = "CreDtTm"))]
    pub cre_dt_tm: IsodateTime,
}

impl Validate for MessageIdentification1 {}


#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct Reason2 {
    #[yaserde(rename = "Desc")]
    #[cfg_attr(feature = "serde", serde(rename = "Desc"))]
    pub desc: Max140Text,
}

impl Validate for Reason2 {}


#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct SimpleIdentificationInformation {
    #[yaserde(rename = "Id")]
    #[cfg_attr(feature = "serde", serde(rename = "Id"))]
    pub id: Max35Text,
}

impl Validate for SimpleIdentificationInformation {}


#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct StatusChangeRequestV02 {
    #[yaserde(rename = "ReqId")]
    #[cfg_attr(feature = "serde", serde(rename = "ReqId"))]
    pub req_id: MessageIdentification1,

    #[yaserde(rename = "TxId")]
    #[cfg_attr(feature = "serde", serde(rename = "TxId"))]
    pub tx_id: SimpleIdentificationInformation,

    #[yaserde(rename = "SubmitrTxRef")]
    #[cfg_attr(feature = "serde", serde(rename = "SubmitrTxRef"))]
    pub submitr_tx_ref: SimpleIdentificationInformation,

    #[yaserde(rename = "ReqdSts")]
    #[cfg_attr(feature = "serde", serde(rename = "ReqdSts"))]
    pub reqd_sts: TransactionStatus3,

    #[yaserde(rename = "ReqRsn")]
    #[cfg_attr(feature = "serde", serde(rename = "ReqRsn"))]
    pub req_rsn: Reason2,
}

impl Validate for StatusChangeRequestV02 {}


#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "n", default_namespace = "n", namespace = "n: urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02")]
pub struct TransactionStatus3 {
    #[yaserde(rename = "Sts")]
    #[cfg_attr(feature = "serde", serde(rename = "Sts"))]
    pub sts: BaselineStatus2Code,
}

impl Validate for TransactionStatus3 {}

impl crate::MxMessage for Document {
    const BUSINESS_AREA: crate::BusinessArea = crate::BusinessArea::tsmt;
    const FUNCTIONALITY: &'static str = "026";
    const VARIANT: &'static str = "001";
    const VERSION: &'static str = "02";
    const MESSAGE_NAME: &'static str = "tsmt.026.001.02";
    const NAMESPACE: &'static str = "urn:iso:std:iso:20022:tech:xsd:tsmt.026.001.02";
}