Skip to main content

instant_epp/extensions/frnic/
contact.rs

1//! Types for EPP FRNIC contact requests
2
3use std::borrow::Cow;
4
5use instant_xml::ser::Context;
6use instant_xml::{Id, ToXml};
7
8use super::{Create, Ext, XMLNS};
9use crate::request::{Extension, Transaction};
10
11impl<'a> Transaction<Ext<Create<ContactCreate<'a>>>> for crate::contact::create::ContactCreate<'a> {}
12
13impl Extension for Ext<Create<ContactCreate<'_>>> {
14    type Response = ();
15}
16
17/// For french TLDs, a contact is either an individual (PP) or a legal
18/// entity (PM). We use the `ContactCreate` extension to differentiate
19/// between the creation of a PP and a PM.
20#[derive(Debug)]
21pub enum ContactCreate<'a> {
22    /// This contact is an individual.
23    NaturalPerson {
24        /// First name of the contact. The `<contact:name>` element
25        /// will be the family name.
26        first_name: Cow<'a, str>,
27    },
28    /// This contact is a legal entity.
29    LegalEntity(Box<LegalEntityInfos<'a>>),
30}
31
32impl<'a> From<ContactCreate<'a>> for Ext<Create<ContactCreate<'a>>> {
33    fn from(data: ContactCreate<'a>) -> Self {
34        Ext {
35            data: Create { data },
36        }
37    }
38}
39
40impl<'a> ContactCreate<'a> {
41    pub fn new_natural_person(first_name: &'a str) -> Self {
42        Self::NaturalPerson {
43            first_name: first_name.into(),
44        }
45    }
46
47    pub fn new_company(
48        siren: Option<&'a str>,
49        vat: Option<&'a str>,
50        trademark: Option<&'a str>,
51        duns: Option<&'a str>,
52        local: Option<&'a str>,
53    ) -> Self {
54        Self::LegalEntity(Box::new(LegalEntityInfos {
55            legal_status: LegalStatus::Company,
56            siren: siren.map(|s| s.into()),
57            vat: vat.map(|v| v.into()),
58            trademark: trademark.map(|t| t.into()),
59            asso: None,
60            duns: duns.map(|d| d.into()),
61            local: local.map(|l| l.into()),
62        }))
63    }
64
65    pub fn new_non_profit(
66        waldec: Option<&'a str>,
67        declaration: Option<&'a str>,
68        publication: Option<Publication<'a>>,
69    ) -> Self {
70        Self::LegalEntity(Box::new(LegalEntityInfos {
71            legal_status: LegalStatus::Association,
72            siren: None,
73            vat: None,
74            trademark: None,
75            asso: Some(Association {
76                waldec: waldec.map(|w| w.into()),
77                declaration: declaration.map(|d| d.into()),
78                publication,
79            }),
80            duns: None,
81            local: None,
82        }))
83    }
84}
85
86impl ToXml for ContactCreate<'_> {
87    fn serialize<W: core::fmt::Write + ?Sized>(
88        &self,
89        _: Option<Id<'_>>,
90        serializer: &mut instant_xml::Serializer<'_, W>,
91    ) -> Result<(), instant_xml::Error> {
92        let contact = serializer.write_start("contact", XMLNS, None::<Context<0>>)?;
93        serializer.end_start()?;
94        match self {
95            Self::NaturalPerson { first_name } => {
96                let element = serializer.write_start("firstName", XMLNS, None::<Context<0>>)?;
97                serializer.end_start()?;
98                first_name.serialize(None, serializer)?;
99                serializer.write_close(element)?;
100            }
101            Self::LegalEntity(infos) => infos.serialize(None, serializer)?,
102        }
103        serializer.write_close(contact)?;
104        Ok(())
105    }
106}
107
108#[derive(Debug, ToXml)]
109#[xml(rename = "legalEntityInfos", ns(XMLNS))]
110pub struct LegalEntityInfos<'a> {
111    pub legal_status: LegalStatus<'a>,
112    pub siren: Option<Cow<'a, str>>,
113    pub vat: Option<Cow<'a, str>>,
114    pub trademark: Option<Cow<'a, str>>,
115    pub asso: Option<Association<'a>>,
116    pub duns: Option<Cow<'a, str>>,
117    pub local: Option<Cow<'a, str>>,
118}
119
120#[derive(Debug)]
121pub enum LegalStatus<'a> {
122    Company,
123    Association,
124    Other(Cow<'a, str>),
125}
126
127impl ToXml for LegalStatus<'_> {
128    fn serialize<W: core::fmt::Write + ?Sized>(
129        &self,
130        _field: Option<Id<'_>>,
131        serializer: &mut instant_xml::Serializer<W>,
132    ) -> Result<(), instant_xml::Error> {
133        let (s, data) = match self {
134            LegalStatus::Company => ("company", None),
135            LegalStatus::Association => ("association", None),
136            LegalStatus::Other(text) => ("other", Some(&text.as_ref()[2..])),
137        };
138
139        let status = serializer.write_start("legalStatus", XMLNS, None::<Context<0>>)?;
140        serializer.write_attr("s", XMLNS, s)?;
141        if let Some(text) = data {
142            serializer.end_start()?;
143            text.serialize(None, serializer)?;
144            serializer.write_close(status)?;
145        } else {
146            serializer.end_empty()?;
147        }
148        Ok(())
149    }
150}
151
152/// Contains information that permits the identification of associations.
153#[derive(Debug, ToXml)]
154#[xml(rename = "asso", ns(XMLNS))]
155pub struct Association<'a> {
156    /// The Waldec registration number. "Waldec" is the acronym for
157    /// the french "[Web des associations librement
158    /// déclarées](https://www.associations.gouv.fr/le-rna-repertoire-national-des-associations.html)"
159    pub waldec: Option<Cow<'a, str>>,
160    /// Date of declaration to the prefecture
161    #[xml(rename = "decl")]
162    pub declaration: Option<Cow<'a, str>>,
163    /// Information of publication in the official gazette
164    #[xml(rename = "publ")]
165    pub publication: Option<Publication<'a>>,
166}
167
168/// Holds information about the publication in the
169/// official gazette for the association.
170#[derive(Debug, ToXml)]
171#[xml(rename = "publ", ns(XMLNS))]
172pub struct Publication<'a> {
173    /// Page number of the announcement
174    #[xml(attribute)]
175    pub page: u32,
176    #[xml(attribute)]
177    /// Number of the announcement
178    pub announce: u32,
179    /// Date of publication
180    #[xml(direct)]
181    pub date: Cow<'a, str>,
182}