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
//! EPP commands relating to draft-ietf-regext-epp-registry-maintenance

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

#[derive(Debug)]
pub struct InfoRequest {
    pub(super) id: String,
    pub return_path: Sender<InfoResponse>,
}

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

#[derive(Debug)]
pub struct InfoResponse {
    pub id: String,
    pub name: Option<String>,
    pub item_type: Vec<String>,
    pub poll_type: Option<PollType>,
    pub environment: Environment,
    pub systems: Vec<System>,
    pub start: DateTime<Utc>,
    pub end: DateTime<Utc>,
    pub created: DateTime<Utc>,
    pub updated: Option<DateTime<Utc>>,
    pub reason: Reason,
    pub detail_url: Option<String>,
    pub descriptions: Vec<Description>,
    pub tlds: Vec<String>,
    pub intervention: Option<Intervention>,
}

#[derive(Debug)]
pub enum PollType {
    Create,
    Update,
    Delete,
    Courtesy,
    End,
}

#[derive(Debug)]
pub struct ListResponse {
    pub items: Vec<ListResponseItem>,
}

#[derive(Debug)]
pub struct ListResponseItem {
    pub id: String,
    pub name: Option<String>,
    pub start: DateTime<Utc>,
    pub end: DateTime<Utc>,
    pub created: DateTime<Utc>,
    pub updated: Option<DateTime<Utc>>,
}

#[derive(Debug)]
pub struct System {
    pub name: String,
    pub host: Option<String>,
    pub impact: Impact,
}

#[derive(Debug)]
pub enum Impact {
    Full,
    Partial,
    None,
}

#[derive(Debug)]
pub struct Intervention {
    pub connection: bool,
    pub implementation: bool,
}

#[derive(Debug)]
pub enum Environment {
    Production,
    Ote,
    Staging,
    Development,
    Custom(String),
}

#[derive(Debug)]
pub enum Reason {
    Planned,
    Emergency,
}

#[derive(Debug)]
pub enum Description {
    Plain(String),
    Html(String),
}

/// Fetches all maintenance items
///
/// # Arguments
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn list(
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<ListResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::MaintenanceList(Box::new(ListRequest {
            return_path: sender,
        })),
        receiver,
    )
    .await
}

/// Fetches a specific maintenance item
///
/// # Arguments
/// * `id` - ID of the maintenance item to retrieve
/// * `client_sender` - Reference to the tokio channel into the client
pub async fn info(
    id: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<InfoResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::MaintenanceInfo(Box::new(InfoRequest {
            id: id.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}