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
use super::super::launch::{
    CodeMark, LaunchAvailabilityCheck, LaunchClaimKey, LaunchClaimsCheck, LaunchCreate,
    LaunchCreateData, LaunchCreateType, LaunchInfo, LaunchInfoData, LaunchPhase, LaunchStatus,
    LaunchStatusType, LaunchTrademarkCheck, LaunchUpdate, Notice, PhaseType,
};
use super::proto;

impl From<&LaunchClaimsCheck> for proto::launch::EPPLaunchCheck {
    fn from(from: &LaunchClaimsCheck) -> Self {
        proto::launch::EPPLaunchCheck {
            check_type: Some(proto::launch::EPPLaunchCheckType::Claims),
            phase: Some((&from.phase).into()),
        }
    }
}

impl From<&LaunchAvailabilityCheck> for proto::launch::EPPLaunchCheck {
    fn from(from: &LaunchAvailabilityCheck) -> Self {
        proto::launch::EPPLaunchCheck {
            check_type: Some(proto::launch::EPPLaunchCheckType::Availability),
            phase: Some((&from.phase).into()),
        }
    }
}

impl From<&LaunchTrademarkCheck> for proto::launch::EPPLaunchCheck {
    fn from(_from: &LaunchTrademarkCheck) -> Self {
        proto::launch::EPPLaunchCheck {
            check_type: Some(proto::launch::EPPLaunchCheckType::Trademark),
            phase: None,
        }
    }
}

impl From<&proto::launch::EPPLaunchClaimKey> for LaunchClaimKey {
    fn from(from: &proto::launch::EPPLaunchClaimKey) -> Self {
        LaunchClaimKey {
            validator_id: from.validator_id.as_ref().map(String::from),
            key: from.key.to_string(),
        }
    }
}

impl From<&LaunchInfo> for proto::launch::EPPLaunchInfo {
    fn from(from: &LaunchInfo) -> Self {
        proto::launch::EPPLaunchInfo {
            include_mark: Some(from.include_mark),
            phase: (&from.phase).into(),
            application_id: from.application_id.as_ref().map(Into::into),
        }
    }
}

impl From<&proto::launch::EPPLaunchInfoData> for LaunchInfoData {
    fn from(from: &proto::launch::EPPLaunchInfoData) -> Self {
        LaunchInfoData {
            phase: (&from.phase).into(),
            application_id: from.application_id.as_ref().map(Into::into),
            status: from.status.as_ref().map(Into::into),
            mark: from.mark.as_ref().map(Into::into),
        }
    }
}

impl From<&LaunchCreate> for proto::launch::EPPLaunchCreate {
    fn from(from: &LaunchCreate) -> Self {
        if from.core_nic.is_empty() {
            proto::launch::EPPLaunchCreate {
                create_type: Some(match from.create_type {
                    LaunchCreateType::Application => {
                        proto::launch::EPPLaunchCreateType::Application
                    }
                    LaunchCreateType::Registration => {
                        proto::launch::EPPLaunchCreateType::Registration
                    }
                }),
                phase: (&from.phase).into(),
                signed_mark: from.signed_mark.as_ref().map(Into::into),
                code_marks: from.code_mark.iter().map(Into::into).collect(),
                notices: from.notices.iter().map(Into::into).collect(),
                augmented_mark: None,
            }
        } else {
            proto::launch::EPPLaunchCreate {
                create_type: Some(match from.create_type {
                    LaunchCreateType::Application => {
                        proto::launch::EPPLaunchCreateType::Application
                    }
                    LaunchCreateType::Registration => {
                        proto::launch::EPPLaunchCreateType::Registration
                    }
                }),
                phase: (&from.phase).into(),
                signed_mark: None,
                code_marks: from.code_mark.iter().map(Into::into).collect(),
                notices: from.notices.iter().map(Into::into).collect(),
                augmented_mark: Some(proto::corenic::EPPAugmentedMark {
                    signed_mark: from.signed_mark.as_ref().map(Into::into),
                    application_info: from
                        .core_nic
                        .iter()
                        .map(|i| proto::corenic::EPPApplicationInfo {
                            info_type: i.info_type.as_ref().map(Into::into),
                            info: i.info.to_string(),
                        })
                        .collect(),
                }),
            }
        }
    }
}

impl From<&LaunchUpdate> for proto::launch::EPPLaunchInfo {
    fn from(from: &LaunchUpdate) -> Self {
        proto::launch::EPPLaunchInfo {
            include_mark: None,
            phase: (&from.phase).into(),
            application_id: from.application_id.as_ref().map(Into::into),
        }
    }
}

impl From<&proto::launch::EPPLaunchCreateData> for LaunchCreateData {
    fn from(from: &proto::launch::EPPLaunchCreateData) -> Self {
        LaunchCreateData {
            phase: (&from.phase).into(),
            application_id: from.application_id.as_ref().map(Into::into),
        }
    }
}

impl From<&CodeMark> for proto::launch::EPPLaunchCodeMark {
    fn from(from: &CodeMark) -> Self {
        proto::launch::EPPLaunchCodeMark {
            code: from.code.as_ref().map(|c| proto::launch::EPPLaunchCode {
                code: c.into(),
                validator_id: from.validator.as_ref().map(Into::into),
            }),
            mark: from.mark.as_ref().map(Into::into),
        }
    }
}

impl From<&Notice> for proto::launch::EPPLaunchNotice {
    fn from(from: &Notice) -> Self {
        proto::launch::EPPLaunchNotice {
            notice_id: proto::launch::EPPLaunchNoticeID {
                code: (&from.notice_id).into(),
                validator_id: from.validator.as_ref().map(Into::into),
            },
            not_after: from.not_after,
            accepted_date: from.accepted_date,
        }
    }
}

impl From<&LaunchPhase> for proto::launch::EPPLaunchPhase {
    fn from(from: &LaunchPhase) -> Self {
        proto::launch::EPPLaunchPhase {
            phase: match from.phase_type {
                PhaseType::Sunrise => proto::launch::EPPLaunchPhaseType::Sunrise,
                PhaseType::Landrush => proto::launch::EPPLaunchPhaseType::Landrush,
                PhaseType::Claims => proto::launch::EPPLaunchPhaseType::Claims,
                PhaseType::Open => proto::launch::EPPLaunchPhaseType::Open,
                PhaseType::Custom => proto::launch::EPPLaunchPhaseType::Custom,
            },
            name: from.phase_name.as_ref().map(Into::into),
        }
    }
}

impl From<&proto::launch::EPPLaunchPhase> for LaunchPhase {
    fn from(from: &proto::launch::EPPLaunchPhase) -> Self {
        Self {
            phase_type: match from.phase {
                proto::launch::EPPLaunchPhaseType::Sunrise => PhaseType::Sunrise,
                proto::launch::EPPLaunchPhaseType::Landrush => PhaseType::Landrush,
                proto::launch::EPPLaunchPhaseType::Claims => PhaseType::Claims,
                proto::launch::EPPLaunchPhaseType::Open => PhaseType::Open,
                proto::launch::EPPLaunchPhaseType::Custom => PhaseType::Custom,
            },
            phase_name: from.name.as_ref().map(Into::into),
        }
    }
}

impl From<&proto::launch::EPPLaunchStatus> for LaunchStatus {
    fn from(from: &proto::launch::EPPLaunchStatus) -> Self {
        LaunchStatus {
            status_type: (&from.status).into(),
            status_name: from.name.as_ref().map(Into::into),
            message: from.message.as_ref().map(Into::into),
        }
    }
}

impl From<&proto::launch::EPPLaunchStatusType> for LaunchStatusType {
    fn from(from: &proto::launch::EPPLaunchStatusType) -> Self {
        match from {
            proto::launch::EPPLaunchStatusType::PendingValidation => Self::PendingValidation,
            proto::launch::EPPLaunchStatusType::Validated => Self::Validated,
            proto::launch::EPPLaunchStatusType::Invalid => Self::Invalid,
            proto::launch::EPPLaunchStatusType::PendingAllocation => Self::PendingAllocation,
            proto::launch::EPPLaunchStatusType::Allocated => Self::Allocated,
            proto::launch::EPPLaunchStatusType::Rejected => Self::Rejected,
            proto::launch::EPPLaunchStatusType::Custom => Self::Custom,
        }
    }
}