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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
use std::{fmt::Debug, sync::Arc};

use oxinat_derive::uri_builder_alias;

use crate::{UriBuilder, Version};

uri_builder_alias!(SysUriBuilder);
ImplSysUriBuilder! {
    (String),
    (AllowUriBuilder<'_>),
    (CatalogsUriBuilder<'_>),
    (DownloadUriBuilder<'_>),
    (MessagesUriBuilder<'_>),
    (RefreshUriBuilder<'_>),
    (NotifyUriBuilder<'_>),
    (SubscribersUriBuilder<'_>),
}
ImplSysUriBuilder! {
    (ArchiveUriBuilder<Parent>, Parent),
    (AsyncOpsUriBuilder<Parent>, Parent),
    (NotificationsUriBuilder<Parent>, Parent),
    (XnatTaskUriBuilder<Parent>, Parent),
}

/// Represents the URI paths available for
/// endpoints meant for interacting with XNAT
/// archive catalogs.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/archive")]
pub struct ArchiveUriBuilder<Parent>
where
    Parent: SysUriBuilder,
{
    #[parent]
    parent: Option<Arc<Parent>>,
}

/// Represents the URI paths available for
/// endpoints meant for doing manipulations
/// against an XNAT archive catalog.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/catalogs")]
pub struct CatalogsUriBuilder<'a>
{
    #[parent]
    parent: Option<&'a ArchiveUriBuilder<String>>
}

/// Represents the URI paths available for
/// endpoints to request a refresh against an
/// XNAT archive catalog.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/refresh")]
#[match_path(path = "{parent}/refresh/{operations}")]
pub struct RefreshUriBuilder<'a>
{
    #[param(map_from=r#"|o: &Vec<_>| o.join(",")"#)]
    operations: Option<Vec<String>>,
    #[parent]
    parent: Option<&'a CatalogsUriBuilder<'a>>,
}

impl CatalogsUriBuilder<'_>
{
    /// Continue the builder into a
    /// `RefreshUriBuilder`.
    pub fn refresh(&self) -> RefreshUriBuilder {
        RefreshUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the URI paths available for
/// endpoints to download the specified catalog.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/download")]
#[match_path(path = "{parent}/download/{catalog_id}")]
pub struct DownloadUriBuilder<'a>
{
    #[param]
    catalog_id: Option<String>,
    #[parent]
    parent: Option<&'a ArchiveUriBuilder<String>>
}

impl DownloadUriBuilder<'_>
{
    /// Produce the
    /// archive/download/{catalog_id}/test URI
    /// endpoint.
    pub fn build_test(&self) -> crate::BuildResult {
        self.build_join("test")
    }

    /// Produce the archive/downloadwithsize URI
    /// endpoint.
    pub fn build_with_size(&self) -> crate::BuildResult {
        self.parent.as_ref().unwrap().build_join("downloadwithsize")
    }

    /// Produce the
    /// archive/download/{catalog_id}/xml URI
    /// endpoint.
    pub fn build_xml(&self) -> crate::BuildResult {
        self.build_join("xml")
    }

    /// Produce the
    /// archive/download/{catalog_id}/zip URI
    /// endpoint.
    pub fn build_zip(&self) -> crate::BuildResult {
        self.build_join("zip")
    }
}

impl ArchiveUriBuilder<String>
{
    /// Continue the builder into a
    /// `CatalogsUriBuilder`.
    pub fn catalogs(&self) -> CatalogsUriBuilder {
        CatalogsUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `DownloadUriBuilder`.
    pub fn download(&self) -> DownloadUriBuilder {
        DownloadUriBuilder::from_parent(&Arc::new(self))
    }

    /// Produce the archive/upload/xml URI
    /// endpoint.
    pub fn build_upload_xml(&self) -> crate::BuildResult {
        self.build_join("upload/xml")
    }
}

/// Represents the URI endpoint paths available to
/// a user to allow/disallow notifications
/// provided by the user.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/notifications")]
pub struct NotificationsUriBuilder<Parent>
where
    Parent: SysUriBuilder,
{
    #[parent]
    parent: Option<Arc<Parent>>
}

/// Represents URI endpoint paths available for
/// managing some allowables for XNAT
/// notifications.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/allow/{name}")]
#[match_path(path = "{parent}/allow/{name}/{setting}")]
pub struct AllowUriBuilder<'a>
{
    #[param]
    name: Option<String>,
    #[param]
    setting: Option<String>,
    #[parent]
    parent: Option<&'a NotificationsUriBuilder<String>>,
}

/// Some supported message type by an XNAT
/// notification system.
#[derive(Clone, Debug, UriBuilder)]
pub enum MessageType {
    ForgotUserName,
    Help,
    PasswordReset,
    Registration,
}

/// Represents URI endpoint paths available for
/// user messaging configuration.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/messages/{message_type}")]
pub struct MessagesUriBuilder<'a>
{
    #[param]
    message_type: Option<MessageType>,
    #[parent]
    parent: Option<&'a NotificationsUriBuilder<String>>,
}

/// Some supported notification type by an XNAT
/// notification system.
#[derive(Clone, Debug, UriBuilder)]
pub enum NotifyType {
    Par,
    Pipeline,
    Registration,
    Transfer,
    Smtp,
    #[match_path(path = "smtp/host/{p0}")]
    SmtpHost(String),
    #[match_path(path = "smtp/password/{p0}")]
    SmtpPassword(String),
    #[match_path(path = "smtp/port/{p0}")]
    SmtpPort(String),
    #[match_path(path = "smtp/property/{p0}")]
    #[match_path(path = "smtp/property/{p0}/{p1}")]
    SmtpProperty(String, Option<String>),
    #[match_path(path = "smtp/protocol/{p0}")]
    SmtpProtocol(String),
    #[match_path(path = "smtp/username/{p0}")]
    SmtpUsername(String),
}

/// Represents URI endpoint paths available for
/// admin notifications to be enabled/disabled.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/notify/{notify_type}")]
pub struct NotifyUriBuilder<'a>
{
    #[param]
    notify_type: Option<NotifyType>,
    #[parent]
    parent: Option<&'a NotificationsUriBuilder<String>>,
}

/// Some supported options available for managing
/// subscriber config options.
#[derive(Clone, Debug, UriBuilder)]
pub enum SubscriberOpt {
    Error,
    Issue,
    NewUser,
    Update,
}

/// Represents URI endpoint paths available for
/// managing subscriber notification
/// configuration.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/subscribers/{subscriber_option}")]
pub struct SubscribersUriBuilder<'a>
{
    #[param]
    subscriber_option: Option<SubscriberOpt>,
    #[parent]
    parent: Option<&'a NotificationsUriBuilder<String>>,
}

impl NotificationsUriBuilder<String>
{
    /// Continue the builder into a
    /// `AllowUriBuilder`.
    pub fn allow(&self) -> AllowUriBuilder {
        AllowUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `MessagesUriBuilder`.
    pub fn messages(&self) -> MessagesUriBuilder {
        MessagesUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `NotifyUriBuilder`.
    pub fn notify(&self) -> NotifyUriBuilder {
        NotifyUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `SubscribersUriBuilder`.
    pub fn subscribers(&self) -> SubscribersUriBuilder {
        SubscribersUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the URI paths available for
/// managing XNAT tasks.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/xnatTask")]
pub struct XnatTaskUriBuilder<Parent>
where
    Parent: SysUriBuilder,
{
    #[parent]
    parent: Option<Arc<Parent>>,
}

impl XnatTaskUriBuilder<String>
{
    /// Produce the
    /// archive/xnatTask/checkNodeConfigurationStatus
    /// URI endpoint.
    pub fn build_check_node_config_status(&self) -> crate::BuildResult {
        self.build_join("checkNodeConfigurationStatus")
    }

    /// Produce the archive/xnatTask/taskList URI
    /// endpoint.
    pub fn build_task_list(&self) -> crate::BuildResult {
        self.build_join("taskList")
    }
}

/// Represents the URI paths available for
/// managing XNAT asyncronous operations.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/asyncOps")]
#[match_path(path = "{parent}/asyncOps/{preference}")]
pub struct AsyncOpsUriBuilder<Parent>
where
    Parent: SysUriBuilder,
{
    #[param]
    preference: Option<String>,
    #[parent]
    parent: Option<Arc<Parent>>,
}

#[derive(Clone, Debug, UriBuilder)]
pub enum LogConfigOpt {
    #[match_path(path = "configs")]
    #[match_path(path = "configs/{p0}")]
    Configs(Option<String>),
    #[match_path(path = "download")]
    #[match_path(path = "download/{p0}")]
    Download(Option<String>),
    Elements,
    Reset,
}

/// Represents the URI paths available for
/// managing XNAT asyncronous operations.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/logs/{config_opt}")]
pub struct LogsUriBuilder<Parent>
where
    Parent: SysUriBuilder,
{
    #[param]
    config_opt: Option<LogConfigOpt>,
    #[parent]
    parent: Option<Arc<Parent>>,
}

/// Represent the URI paths available for
/// endpoints meant for interacting with an XNAT
/// archive catalog.
pub trait SystemUri: Version {
    /// URI endpoint to access the archive catalog
    /// API.
    #[inline]
    fn archive(&self) -> ArchiveUriBuilder<String> {
        ArchiveUriBuilder::from_parent(self.root_uri().into())
    }

    /// URI endpoint to interact with XNAT async
    /// ops API.
    #[inline]
    fn async_ops(&self) -> AsyncOpsUriBuilder<String> {
        AsyncOpsUriBuilder::from_parent(self.root_uri().into())
    }

    /// URI endpoint to interact with XNAT log
    /// configurations.
    #[inline]
    fn logs(&self) -> LogsUriBuilder<String> {
        LogsUriBuilder::from_parent(self.root_uri().into())
    }

    /// URI endpoint to interact with XNAT
    /// notifications API.
    #[inline]
    fn notifications(&self) -> NotificationsUriBuilder<String> {
        NotificationsUriBuilder::from_parent(self.root_uri().into())
    }

    /// URI enpoint to interact with XNAT task
    /// API.
    #[inline]
    fn xnat_task(&self) -> XnatTaskUriBuilder<String> {
        XnatTaskUriBuilder::from_parent(self.root_uri().into())
    }
}