1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//! Types for EPP RGP restore report

use epp_client_macros::*;

use crate::epp::object::data::HostObjList;
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::domain::update::{DomainChangeInfo, DomainUpdate, DomainUpdateData};
use crate::epp::request::{CommandWithExtension, Extension};
use crate::epp::xml::{
    EPP_DOMAIN_RGP_EXT_SCHEMA_LOCATION, EPP_DOMAIN_RGP_EXT_XMLNS, EPP_DOMAIN_XMLNS,
};
use chrono::{DateTime, SecondsFormat, Utc};
use serde::{Deserialize, Serialize};

/// Type that represents the <epp> request for domain rgp restore report command
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainRgpRestoreReport, EppDomainRgpRestoreReportResponse};
/// use epp_client::epp::generate_client_tr_id;
/// use chrono::{DateTime, NaiveDate};
/// use std::str::FromStr;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     let pre_data =
///         "Pre-delete registration data goes here. Both XML and free text are allowed.";
///     let post_data =
///         "Post-restore registration data goes here. Both XML and free text are allowed.";
///     let deleted_at = DateTime::from_str("2021-07-10T22:00:00.0Z").unwrap();
///     let restored_at = DateTime::from_str("2021-07-20T22:00:00.0Z").unwrap();
///     let restore_reason = "Registrant error.";
///     let statements = vec![
///         "This registrar has not restored the Registered Name in order to assume the rights to use or sell the Registered Name for itself or for any third party.",
///         "The information in this report is true to best of this registrar's knowledge, and this registrar acknowledges that intentionally supplying false information in this report shall constitute an incurable material breach of the Registry-Registrar Agreement.",
///     ];
///     let other = "Supporting information goes here.";
///
///     // Create an EppDomainRgpRestoreReport instance
///     let domain_restore_report = EppDomainRgpRestoreReport::new(
///         "eppdev.com",
///         pre_data,
///         post_data,
///         deleted_at,
///         restored_at,
///         restore_reason,
///         statements,
///         other,
///         generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainRgpRestoreReportResponse
///     let response = client.transact::<_, EppDomainRgpRestoreReportResponse>(&domain_restore_report).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainRgpRestoreReport =
    EppObject<CommandWithExtension<DomainUpdate<HostObjList>, RgpRestoreReport>>;

/// Type corresponding to the &lt;report&gt; section in the EPP rgp restore extension
#[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportData {
    /// The pre-delete registration date
    #[serde(rename = "preData")]
    pre_data: StringValue,
    /// The post-delete registration date
    #[serde(rename = "postData")]
    post_data: StringValue,
    /// The domain deletion date
    #[serde(rename = "delTime")]
    deleted_at: StringValue,
    /// The domain restore request date
    #[serde(rename = "resTime")]
    restored_at: StringValue,
    /// The reason for domain restoration
    #[serde(rename = "resReason")]
    restore_reason: StringValue,
    /// The registrar's statements on the domain restoration
    #[serde(rename = "statement")]
    statements: Vec<StringValue>,
    /// Other remarks for domain restoration
    other: StringValue,
}

/// Type corresponding to the &lt;restore&gt; section in the rgp restore extension
#[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportSection {
    /// The value of the op attribute for the &lt;restore&gt; tag
    op: String,
    /// Data for the &lt;report&gt; tag
    report: RgpRestoreReportData,
}

#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "update")]
/// Type for EPP XML &lt;check&gt; command for domains
pub struct RgpRestoreReport {
    /// XML namespace for the RGP restore extension
    xmlns: String,
    /// XML schema location for the RGP restore extension
    #[serde(rename = "xsi:schemaLocation")]
    schema_location: String,
    /// The object holding the list of domains to be checked
    restore: RgpRestoreReportSection,
}

impl EppDomainRgpRestoreReport {
    /// Creates a new EppObject for domain rgp restore report corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn new(
        name: &str,
        pre_data: &str,
        post_data: &str,
        deleted_at: DateTime<Utc>,
        restored_at: DateTime<Utc>,
        restore_reason: &str,
        statements: Vec<&str>,
        other: &str,
        client_tr_id: &str,
    ) -> EppDomainRgpRestoreReport {
        let statements = statements
            .iter()
            .map(|s| s.to_string_value())
            .collect::<Vec<StringValue>>();

        let command = CommandWithExtension::<DomainUpdate<HostObjList>, RgpRestoreReport> {
            command: DomainUpdate {
                domain: DomainUpdateData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    add: None,
                    remove: None,
                    change_info: Some(DomainChangeInfo {
                        registrant: None,
                        auth_info: None,
                    }),
                },
            },
            extension: Some(Extension {
                data: RgpRestoreReport {
                    xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
                    schema_location: EPP_DOMAIN_RGP_EXT_SCHEMA_LOCATION.to_string(),
                    restore: RgpRestoreReportSection {
                        op: "report".to_string(),
                        report: RgpRestoreReportData {
                            pre_data: pre_data.to_string_value(),
                            post_data: post_data.to_string_value(),
                            deleted_at: deleted_at
                                .to_rfc3339_opts(SecondsFormat::AutoSi, true)
                                .to_string_value(),
                            restored_at: restored_at
                                .to_rfc3339_opts(SecondsFormat::AutoSi, true)
                                .to_string_value(),
                            restore_reason: restore_reason.to_string_value(),
                            statements: statements,
                            other: other.to_string_value(),
                        },
                    },
                },
            }),
            client_tr_id: client_tr_id.to_string_value(),
        };

        EppObject::build(command)
    }
}