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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
//! EPP commands relating to nominet specific features

use super::{CommandResponse, RequestMessage, Sender};
use chrono::prelude::*;

#[derive(Debug)]
pub struct HandshakeAcceptRequest {
    pub(super) case_id: String,
    pub(super) registrant: Option<String>,
    pub return_path: Sender<HandshakeResponse>,
}

#[derive(Debug)]
pub struct HandshakeRejectRequest {
    pub(super) case_id: String,
    pub return_path: Sender<HandshakeResponse>,
}

#[derive(Debug)]
pub struct HandshakeResponse {
    pub case_id: String,
    pub domains: Vec<String>,
}

#[derive(Debug)]
pub struct ReleaseRequest {
    pub(super) registrar_tag: String,
    pub(super) object: Object,
    pub return_path: Sender<ReleaseResponse>,
}

#[derive(Debug)]
pub enum Object {
    Domain(String),
    Registrant(String),
}

#[derive(Debug)]
pub struct ReleaseResponse {
    pub pending: bool,
    pub message: Option<String>,
}

#[derive(Debug)]
pub struct ContactValidateRequest {
    pub(super) contact_id: String,
    pub return_path: Sender<ContactValidateResponse>,
}

#[derive(Debug)]
pub struct ContactValidateResponse {}

#[derive(Debug)]
pub struct LockRequest {
    pub(super) object: Object,
    pub(super) lock_type: String,
    pub return_path: Sender<LockResponse>,
}

#[derive(Debug)]
pub struct LockResponse {}

#[derive(Debug)]
pub struct TagListRequest {
    pub return_path: Sender<TagListResponse>,
}

/// Response to a tag list query
#[derive(Debug)]
pub struct TagListResponse {
    /// Tags returned
    pub tags: Vec<Tag>,
}

#[derive(Debug)]
pub struct Tag {
    /// Tag ID
    pub tag: String,
    /// Legal name of the tag
    pub name: String,
    /// Trading name of the tag
    pub trading_name: Option<String>,
    /// Does this tag require handshaking
    pub handshake: bool,
}

#[derive(Debug)]
pub struct CancelData {
    pub domain_name: String,
    pub originator: String,
}

#[derive(Debug)]
pub struct ReleaseData {
    pub account_id: String,
    pub account_moved: bool,
    pub from: String,
    pub registrar_tag: String,
    pub domains: Vec<String>,
}

#[derive(Debug)]
pub struct RegistrarChangeData {
    pub originator: String,
    pub registrar_tag: String,
    pub case_id: Option<String>,
    pub domains: Vec<super::domain::InfoResponse>,
    pub contact: super::contact::InfoResponse,
}

#[derive(Debug)]
pub struct HostCancelData {
    pub host_objects: Vec<String>,
    pub domain_names: Vec<String>,
}

#[derive(Debug)]
pub struct ProcessData {
    pub stage: ProcessStage,
    pub contact: super::contact::InfoResponse,
    pub process_type: String,
    pub suspend_date: Option<DateTime<Utc>>,
    pub cancel_date: Option<DateTime<Utc>>,
    pub domain_names: Vec<String>,
}

#[derive(Debug)]
pub enum ProcessStage {
    Initial,
    Updated,
}

#[derive(Debug)]
pub struct SuspendData {
    pub reason: String,
    pub cancel_date: Option<DateTime<Utc>>,
    pub domain_names: Vec<String>,
}

#[derive(Debug)]
pub struct DomainFailData {
    pub reason: String,
    pub domain_name: String,
}

#[derive(Debug)]
pub struct RegistrantTransferData {
    pub originator: String,
    pub account_id: String,
    pub old_account_id: String,
    pub case_id: Option<String>,
    pub domain_names: Vec<String>,
    pub contact: super::contact::InfoResponse,
}

#[derive(Debug)]
pub enum DataQualityStatus {
    Valid,
    Invalid,
}

#[derive(Debug)]
pub struct DataQualityData {
    pub status: DataQualityStatus,
    pub reason: Option<String>,
    pub date_commenced: Option<DateTime<Utc>>,
    pub date_to_suspend: Option<DateTime<Utc>>,
    pub lock_applied: Option<bool>,
    pub domains: Option<Vec<String>>,
}

/// Accepts a pending transfer in
///
/// # Arguments
/// * `case_id` - The Nominet assigned case ID
/// * `registrant` - Optional account to assign the domain to
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn handshake_accept(
    case_id: &str,
    registrant: Option<&str>,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<HandshakeResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetAccept(Box::new(HandshakeAcceptRequest {
            case_id: case_id.to_owned(),
            registrant: registrant.map(Into::into),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Rejects a pending transfer in
///
/// # Arguments
/// * `case_id` - The Nominet assigned case ID
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn handshake_reject(
    case_id: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<HandshakeResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetReject(Box::new(HandshakeRejectRequest {
            case_id: case_id.to_owned(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Requests the transfer out of a domain
///
/// # Arguments
/// * `registrar_tag` - Target registrar TAG
/// * `object` - Object to release
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn release(
    registrar_tag: &str,
    object: Object,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<ReleaseResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetRelease(Box::new(ReleaseRequest {
            registrar_tag: registrar_tag.to_owned(),
            object,
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Fetches a list of registered tags
///
/// # Arguments
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn tag_list(
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<TagListResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetTagList(Box::new(TagListRequest {
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Sets the valid flag on contact data quality
///
/// # Arguments
/// * `id` - ID of the contact object
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn contact_validate(
    id: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<ContactValidateResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetContactValidate(Box::new(ContactValidateRequest {
            contact_id: id.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Locks contact's domains / specific domain
///
/// # Arguments
/// * `object` - Contact / domain
/// * `lock_type` - Reason for locking
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn lock(
    object: Object,
    lock_type: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<LockResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetLock(Box::new(LockRequest {
            object,
            lock_type: lock_type.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Unlocks contact's domains / specific domain
///
/// # Arguments
/// * `object` - Contact / domain
/// * `lock_type` - Reason for locking
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn unlock(
    object: Object,
    lock_type: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<LockResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::NominetUnlock(Box::new(LockRequest {
            object,
            lock_type: lock_type.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}