1
#[derive(Debug, Clone, PartialEq)]
2
pub enum Param {
3
    AltRep(AlternateRepresentationParam),
4
    CommonName(CommonNameParam),
5
    ValueType(ValueTypeParam),
6
    TimeZoneId(TimeZoneIdParam),
7
    Language(LanguageParam),
8
    DirectoryEntryReference(DirectoryEntryReferenceParam),
9
    SentBy(SentByParam),
10
    Range(RangeParam),
11
    FormatType(FormatTypeParam),
12
    Encoding(EncodingParam),
13
    CalendarUserType(CalendarUserTypeParam),
14
    Members(MembersParam),
15
    Role(RoleParam),
16
    ParticipationStatus(ParticipationStatusParam),
17
    Rsvp(RsvpParam),
18
    DelegatedTo(DelegatedToParam),
19
    DelegatedFrom(DelegatedFromParam),
20
    RelationshipType(RelationshipTypeParam),
21
    FreeBusyTimeType(FreeBusyTimeTypeParam),
22
    TriggerRelationship(TriggerRelationshipParam),
23
    Other { name: String, value: String },
24
    Others { name: String, values: Vec<String> },
25
}
26

            
27
pub trait ParamInner<T> {
28
    fn param_inner(&self) -> Option<&T>;
29
}
30

            
31
macro_rules! impl_param_inner {
32
    ($for_type:ty, $variant:ident) => {
33
        impl $crate::model::param::ParamInner<$for_type> for Param {
34
24
            fn param_inner(&self) -> Option<&$for_type> {
35
24
                match self {
36
18
                    $crate::model::param::Param::$variant(p) => Some(p),
37
6
                    _ => None,
38
                }
39
24
            }
40
        }
41
    };
42
}
43

            
44
#[derive(Debug, Clone, PartialEq)]
45
pub struct AlternateRepresentationParam {
46
    pub uri: String,
47
}
48

            
49
impl_param_inner!(AlternateRepresentationParam, AltRep);
50

            
51
#[derive(Debug, Clone, PartialEq)]
52
pub struct CommonNameParam {
53
    pub name: String,
54
}
55

            
56
impl_param_inner!(CommonNameParam, CommonName);
57

            
58
#[derive(Debug, Clone, PartialEq)]
59
pub struct ValueTypeParam {
60
    pub value: Value,
61
}
62

            
63
impl_param_inner!(ValueTypeParam, ValueType);
64

            
65
#[derive(Debug, Clone, PartialEq)]
66
pub struct TimeZoneIdParam {
67
    pub tz_id: String,
68
    pub unique: bool,
69
}
70

            
71
impl_param_inner!(TimeZoneIdParam, TimeZoneId);
72

            
73
#[derive(Debug, Clone, PartialEq)]
74
pub struct LanguageParam {
75
    pub language: LanguageTag,
76
}
77

            
78
impl_param_inner!(LanguageParam, Language);
79

            
80
#[derive(Debug, Clone, PartialEq)]
81
pub struct DirectoryEntryReferenceParam {
82
    pub uri: String,
83
}
84

            
85
impl_param_inner!(DirectoryEntryReferenceParam, DirectoryEntryReference);
86

            
87
#[derive(Debug, Clone, PartialEq)]
88
pub struct SentByParam {
89
    pub address: String,
90
}
91

            
92
impl_param_inner!(SentByParam, SentBy);
93

            
94
#[derive(Debug, Clone, PartialEq)]
95
pub struct RangeParam {
96
    pub range: Range,
97
}
98

            
99
impl_param_inner!(RangeParam, Range);
100

            
101
#[derive(Debug, Clone, PartialEq)]
102
pub struct FormatTypeParam {
103
    pub type_name: String,
104
    pub sub_type_name: String,
105
}
106

            
107
impl_param_inner!(FormatTypeParam, FormatType);
108

            
109
#[derive(Debug, Clone, PartialEq)]
110
pub struct EncodingParam {
111
    pub encoding: Encoding,
112
}
113

            
114
impl_param_inner!(EncodingParam, Encoding);
115

            
116
#[derive(Debug, Clone, PartialEq)]
117
pub struct CalendarUserTypeParam {
118
    pub cu_type: CalendarUserType,
119
}
120

            
121
impl_param_inner!(CalendarUserTypeParam, CalendarUserType);
122

            
123
#[derive(Debug, Clone, PartialEq)]
124
pub struct MembersParam {
125
    pub members: Vec<String>,
126
}
127

            
128
impl_param_inner!(MembersParam, Members);
129

            
130
#[derive(Debug, Clone, PartialEq)]
131
pub struct RoleParam {
132
    pub role: Role,
133
}
134

            
135
impl_param_inner!(RoleParam, Role);
136

            
137
#[derive(Debug, Clone, PartialEq)]
138
pub struct ParticipationStatusParam {
139
    pub status: ParticipationStatusUnknown,
140
}
141

            
142
impl_param_inner!(ParticipationStatusParam, ParticipationStatus);
143

            
144
#[derive(Debug, Clone, PartialEq)]
145
pub struct RsvpParam {
146
    pub rsvp: bool,
147
}
148

            
149
impl_param_inner!(RsvpParam, Rsvp);
150

            
151
#[derive(Debug, Clone, PartialEq)]
152
pub struct DelegatedToParam {
153
    pub delegates: Vec<String>,
154
}
155

            
156
impl_param_inner!(DelegatedToParam, DelegatedTo);
157

            
158
#[derive(Debug, Clone, PartialEq)]
159
pub struct DelegatedFromParam {
160
    pub delegators: Vec<String>,
161
}
162

            
163
impl_param_inner!(DelegatedFromParam, DelegatedFrom);
164

            
165
#[derive(Debug, Clone, PartialEq)]
166
pub struct RelationshipTypeParam {
167
    pub relationship: RelationshipType,
168
}
169

            
170
impl_param_inner!(RelationshipTypeParam, RelationshipType);
171

            
172
#[derive(Debug, Clone, PartialEq)]
173
pub struct FreeBusyTimeTypeParam {
174
    pub fb_type: FreeBusyTimeType,
175
}
176

            
177
impl_param_inner!(FreeBusyTimeTypeParam, FreeBusyTimeType);
178

            
179
#[derive(Debug, Clone, PartialEq)]
180
pub struct TriggerRelationshipParam {
181
    pub trigger_relationship: TriggerRelationship,
182
}
183

            
184
impl_param_inner!(TriggerRelationshipParam, TriggerRelationship);
185

            
186
impl Display for TimeTransparency {
187
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
188
        match self {
189
            TimeTransparency::Opaque => write!(f, "OPAQUE"),
190
            TimeTransparency::Transparent => write!(f, "TRANSPARENT"),
191
        }
192
    }
193
}
194

            
195
#[derive(Debug, Clone, Eq, PartialEq, Default)]
196
pub enum ParticipationStatusEvent {
197
    #[default]
198
    NeedsAction,
199
    Accepted,
200
    Declined,
201
    Tentative,
202
    Delegated,
203
    XName(String),
204
    IanaToken(String),
205
}
206

            
207
impl From<ParticipationStatusEvent> for ParticipationStatusUnknown {
208
14
    fn from(value: ParticipationStatusEvent) -> ParticipationStatusUnknown {
209
14
        match value {
210
            ParticipationStatusEvent::NeedsAction => ParticipationStatusUnknown::NeedsAction,
211
14
            ParticipationStatusEvent::Accepted => ParticipationStatusUnknown::Accepted,
212
            ParticipationStatusEvent::Declined => ParticipationStatusUnknown::Declined,
213
            ParticipationStatusEvent::Tentative => ParticipationStatusUnknown::Tentative,
214
            ParticipationStatusEvent::Delegated => ParticipationStatusUnknown::Delegated,
215
            ParticipationStatusEvent::XName(name) => ParticipationStatusUnknown::XName(name),
216
            ParticipationStatusEvent::IanaToken(token) => {
217
                ParticipationStatusUnknown::IanaToken(token)
218
            }
219
        }
220
14
    }
221
}
222

            
223
pub enum ParticipationStatusToDo {
224
    NeedsAction,
225
    Accepted,
226
    Declined,
227
    Tentative,
228
    Delegated,
229
    Completed,
230
    InProcess,
231
    XName(String),
232
    IanaToken(String),
233
}
234

            
235
impl From<ParticipationStatusToDo> for ParticipationStatusUnknown {
236
12
    fn from(value: ParticipationStatusToDo) -> ParticipationStatusUnknown {
237
12
        match value {
238
12
            ParticipationStatusToDo::NeedsAction => ParticipationStatusUnknown::NeedsAction,
239
            ParticipationStatusToDo::Accepted => ParticipationStatusUnknown::Accepted,
240
            ParticipationStatusToDo::Declined => ParticipationStatusUnknown::Declined,
241
            ParticipationStatusToDo::Tentative => ParticipationStatusUnknown::Tentative,
242
            ParticipationStatusToDo::Delegated => ParticipationStatusUnknown::Delegated,
243
            ParticipationStatusToDo::Completed => ParticipationStatusUnknown::Completed,
244
            ParticipationStatusToDo::InProcess => ParticipationStatusUnknown::InProcess,
245
            ParticipationStatusToDo::XName(name) => ParticipationStatusUnknown::XName(name),
246
            ParticipationStatusToDo::IanaToken(token) => {
247
                ParticipationStatusUnknown::IanaToken(token)
248
            }
249
        }
250
12
    }
251
}
252

            
253
pub enum ParticipationStatusJournal {
254
    NeedsAction,
255
    Accepted,
256
    Declined,
257
    XName(String),
258
    IanaToken(String),
259
}
260

            
261
impl From<ParticipationStatusJournal> for ParticipationStatusUnknown {
262
12
    fn from(value: ParticipationStatusJournal) -> ParticipationStatusUnknown {
263
12
        match value {
264
12
            ParticipationStatusJournal::NeedsAction => ParticipationStatusUnknown::NeedsAction,
265
            ParticipationStatusJournal::Accepted => ParticipationStatusUnknown::Accepted,
266
            ParticipationStatusJournal::Declined => ParticipationStatusUnknown::Declined,
267
            ParticipationStatusJournal::XName(name) => ParticipationStatusUnknown::XName(name),
268
            ParticipationStatusJournal::IanaToken(token) => {
269
                ParticipationStatusUnknown::IanaToken(token)
270
            }
271
        }
272
12
    }
273
}
274

            
275
pub trait OtherParamsBuilder {
276
    fn add_iana_param<N: ToString, V: ToString>(self, name: N, value: V) -> Self;
277

            
278
    fn add_iana_param_values<N: ToString>(self, name: N, values: Vec<String>) -> Self;
279

            
280
    fn add_x_param<N: ToString, V: ToString>(self, name: N, value: V) -> Self;
281

            
282
    fn add_x_param_values<N: ToString>(self, name: N, values: Vec<String>) -> Self;
283
}
284

            
285
macro_rules! impl_other_params_builder {
286
    ($builder:ty) => {
287
        impl crate::model::param::OtherParamsBuilder for $builder {
288
18
            fn add_iana_param<N: ToString, V: ToString>(mut self, name: N, value: V) -> Self {
289
18
                self.inner.params.push(Param::Other {
290
18
                    name: name.to_string(),
291
18
                    value: value.to_string(),
292
18
                });
293
18
                self
294
18
            }
295

            
296
2
            fn add_iana_param_values<N: ToString>(mut self, name: N, values: Vec<String>) -> Self {
297
2
                self.inner.params.push(Param::Others {
298
2
                    name: name.to_string(),
299
2
                    values,
300
2
                });
301
2
                self
302
2
            }
303

            
304
18
            fn add_x_param<N: ToString, V: ToString>(mut self, name: N, value: V) -> Self {
305
18
                self.inner.params.push(Param::Other {
306
18
                    name: name.to_string(),
307
18
                    value: value.to_string(),
308
18
                });
309
18
                self
310
18
            }
311

            
312
2
            fn add_x_param_values<N: ToString>(mut self, name: N, values: Vec<String>) -> Self {
313
2
                self.inner.params.push(Param::Others {
314
2
                    name: name.to_string(),
315
2
                    values,
316
2
                });
317
2
                self
318
2
            }
319
        }
320
    };
321
}
322

            
323
pub(crate) use impl_other_params_builder;
324
use std::fmt;
325
use std::fmt::{Display, Formatter};
326

            
327
macro_rules! impl_other_component_params_builder {
328
    ($builder:ident<$p:ident$(,$oth:ident),*>) => {
329
        impl<$p $(,$oth)*> crate::model::param::OtherParamsBuilder for $builder<$p $(,$oth)*>
330
        where
331
            $p: crate::model::property::AddComponentProperty,
332
        {
333
554
            fn add_iana_param<N: ToString, V: ToString>(mut self, name: N, value: V) -> Self {
334
554
                self.inner.params.push(Param::Other {
335
554
                    name: name.to_string(),
336
554
                    value: value.to_string(),
337
554
                });
338
554
                self
339
554
            }
340

            
341
            fn add_iana_param_values<N: ToString>(mut self, name: N, values: Vec<String>) -> Self {
342
                self.inner.params.push(Param::Others {
343
                    name: name.to_string(),
344
                    values,
345
                });
346
                self
347
            }
348

            
349
612
            fn add_x_param<N: ToString, V: ToString>(mut self, name: N, value: V) -> Self {
350
612
                self.inner.params.push(Param::Other {
351
612
                    name: name.to_string(),
352
612
                    value: value.to_string(),
353
612
                });
354
612
                self
355
612
            }
356

            
357
            fn add_x_param_values<N: ToString>(mut self, name: N, values: Vec<String>) -> Self {
358
                self.inner.params.push(Param::Others {
359
                    name: name.to_string(),
360
                    values,
361
                });
362
                self
363
            }
364
        }
365
    };
366
}
367

            
368
pub(crate) use impl_other_component_params_builder;
369

            
370
macro_rules! altrep_param {
371
    () => {
372
        // TODO no generic URI representation for Rust? Maybe extract the URI parser in this crate and
373
        //      make that into a URI crate.
374
90
        pub fn add_alternate_representation(mut self, value: &str) -> Self {
375
90
            self.inner.params.push(Param::AltRep(
376
90
                $crate::model::param::AlternateRepresentationParam {
377
90
                    uri: value.to_string(),
378
90
                },
379
90
            ));
380
90
            self
381
90
        }
382
    };
383
}
384

            
385
pub(crate) use altrep_param;
386

            
387
macro_rules! language_param {
388
    () => {
389
154
        pub fn add_language(mut self, language: $crate::common::LanguageTag) -> Self {
390
154
            self.inner
391
154
                .params
392
154
                .push(Param::Language($crate::model::param::LanguageParam {
393
154
                    language,
394
154
                }));
395
154
            self
396
154
        }
397
    };
398
}
399

            
400
pub(crate) use language_param;
401

            
402
macro_rules! tz_id_param {
403
    () => {
404
68
        pub fn add_tz_id<V: ToString>(mut self, tz_id: V, unique: bool) -> Self {
405
68
            self.inner
406
68
                .params
407
68
                .push(Param::TimeZoneId($crate::model::param::TimeZoneIdParam {
408
68
                    tz_id: tz_id.to_string(),
409
68
                    unique,
410
68
                }));
411
68
            self
412
68
        }
413
    };
414
}
415

            
416
pub(crate) use tz_id_param;
417

            
418
macro_rules! sent_by_param {
419
    () => {
420
        // TODO should be a URI
421
30
        pub fn add_sent_by(mut self, value: &str) -> Self {
422
30
            self.inner
423
30
                .params
424
30
                .push(Param::SentBy($crate::model::param::SentByParam {
425
30
                    address: value.to_string(),
426
30
                }));
427
30
            self
428
30
        }
429
    };
430
}
431

            
432
pub(crate) use sent_by_param;
433

            
434
macro_rules! common_name_param {
435
    () => {
436
30
        pub fn add_common_name<V: ToString>(mut self, value: V) -> Self {
437
30
            self.inner
438
30
                .params
439
30
                .push(Param::CommonName($crate::model::param::CommonNameParam {
440
30
                    name: value.to_string(),
441
30
                }));
442
30
            self
443
30
        }
444
    };
445
}
446

            
447
pub(crate) use common_name_param;
448

            
449
macro_rules! directory_entry_reference_param {
450
    () => {
451
        // TODO should be a URI
452
30
        pub fn add_directory_entry_reference(mut self, value: &str) -> Self {
453
30
            self.inner.params.push(Param::DirectoryEntryReference(
454
30
                $crate::model::param::DirectoryEntryReferenceParam {
455
30
                    uri: value.to_string(),
456
30
                },
457
30
            ));
458
30
            self
459
30
        }
460
    };
461
}
462

            
463
use crate::common::{
464
    CalendarUserType, Encoding, FreeBusyTimeType, LanguageTag, ParticipationStatusUnknown, Range,
465
    RelationshipType, Role, TimeTransparency, TriggerRelationship, Value,
466
};
467
pub(crate) use directory_entry_reference_param;
468

            
469
macro_rules! add_is_utc {
470
    () => {
471
44
        pub fn set_is_utc(mut self) -> Self {
472
44
            self.inner.value.set_utc(true);
473
44
            self
474
44
        }
475
    };
476
}
477

            
478
pub(crate) use add_is_utc;