1
use crate::common::TimeTransparency;
2
use crate::model::component::{
3
    add_alarms, add_attach, add_categories, add_class, add_comment, add_contact, add_created,
4
    add_date_time_end, add_date_time_stamp, add_date_time_start, add_description, add_duration,
5
    add_exception_date_times, add_geographic_position, add_last_modified, add_location,
6
    add_organizer, add_priority, add_recurrence_date, add_recurrence_id, add_recurrence_rule,
7
    add_related, add_request_status, add_resources, add_sequence, add_summary,
8
    add_unique_identifier, add_url,
9
};
10
use crate::model::component::{
11
    impl_finish_component_build, impl_other_component_properties, AddAlarmComponent,
12
    AlarmComponent, CalendarComponent,
13
};
14
use crate::model::impl_component_access;
15
use crate::model::object::ICalObjectBuilder;
16
use crate::model::param::ParticipationStatusEvent;
17
use crate::model::property::{
18
    AddComponentProperty, AttendeePropertyBuilder, ComponentProperty, XComponentPropertyBuilder,
19
};
20
use crate::model::property::{
21
    IanaComponentPropertyBuilder, StatusEvent, StatusPropertyBuilder,
22
    TimeTransparencyPropertyBuilder,
23
};
24

            
25
#[derive(Debug, PartialEq)]
26
pub struct EventComponent {
27
    pub(crate) properties: Vec<ComponentProperty>,
28
    pub(crate) alarms: Vec<CalendarComponent>,
29
}
30

            
31
impl_component_access!(EventComponent);
32

            
33
impl EventComponent {
34
154
    pub fn new() -> Self {
35
154
        EventComponent {
36
154
            properties: Vec::new(),
37
154
            alarms: Vec::new(),
38
154
        }
39
154
    }
40

            
41
6
    pub fn alarms(&self) -> &[CalendarComponent] {
42
6
        &self.alarms
43
6
    }
44
}
45

            
46
impl Default for EventComponent {
47
    fn default() -> Self {
48
        Self::new()
49
    }
50
}
51

            
52
pub struct EventComponentBuilder {
53
    owner: ICalObjectBuilder,
54
    inner: EventComponent,
55
}
56

            
57
impl EventComponentBuilder {
58
14
    pub(crate) fn new(owner: ICalObjectBuilder) -> Self {
59
14
        EventComponentBuilder {
60
14
            owner,
61
14
            inner: EventComponent::new(),
62
14
        }
63
14
    }
64

            
65
    add_date_time_stamp!();
66

            
67
    add_unique_identifier!();
68

            
69
    add_date_time_start!();
70

            
71
    add_class!();
72

            
73
    add_created!();
74

            
75
    add_description!();
76

            
77
    add_geographic_position!();
78

            
79
    add_last_modified!();
80

            
81
    add_location!();
82

            
83
    add_organizer!();
84

            
85
    add_priority!();
86

            
87
    add_sequence!();
88

            
89
14
    pub fn add_status(self, value: StatusEvent) -> StatusPropertyBuilder<Self> {
90
14
        StatusPropertyBuilder::new(self, value.into())
91
14
    }
92

            
93
    add_summary!();
94

            
95
14
    pub fn add_time_transparency(
96
14
        self,
97
14
        value: TimeTransparency,
98
14
    ) -> TimeTransparencyPropertyBuilder<Self> {
99
14
        TimeTransparencyPropertyBuilder::new(self, value)
100
14
    }
101

            
102
    add_url!();
103

            
104
    add_recurrence_id!();
105

            
106
    add_recurrence_rule!();
107

            
108
    add_date_time_end!();
109

            
110
    add_duration!();
111

            
112
    add_attach!();
113

            
114
14
    pub fn add_attendee(
115
14
        self,
116
14
        value: &str,
117
14
    ) -> AttendeePropertyBuilder<Self, ParticipationStatusEvent> {
118
14
        AttendeePropertyBuilder::new(self, value.to_string())
119
14
    }
120

            
121
    add_categories!();
122

            
123
    add_comment!();
124

            
125
    add_contact!();
126

            
127
    add_exception_date_times!();
128

            
129
    add_request_status!();
130

            
131
    add_related!();
132

            
133
    add_resources!();
134

            
135
    add_recurrence_date!();
136

            
137
    impl_other_component_properties!(
138
        XComponentPropertyBuilder,
139
        IanaComponentPropertyBuilder,
140
        EventComponentBuilder
141
    );
142

            
143
    add_alarms!();
144

            
145
    impl_finish_component_build!(CalendarComponent::Event);
146
}
147

            
148
impl AddComponentProperty for EventComponentBuilder {
149
434
    fn add_property(&mut self, property: ComponentProperty) {
150
434
        self.inner.properties.push(property);
151
434
    }
152
}
153

            
154
impl AddAlarmComponent for EventComponentBuilder {
155
36
    fn add_alarm(mut self, alarm: AlarmComponent) -> Self {
156
36
        self.inner.alarms.push(CalendarComponent::Alarm(alarm));
157
36
        self
158
36
    }
159
}