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

            
19
#[derive(Debug, PartialEq)]
20
pub struct ToDoComponent {
21
    pub(crate) properties: Vec<ComponentProperty>,
22
    pub(crate) alarms: Vec<CalendarComponent>,
23
}
24

            
25
impl_component_access!(ToDoComponent);
26

            
27
impl ToDoComponent {
28
24
    pub(crate) fn new() -> Self {
29
24
        ToDoComponent {
30
24
            properties: Vec::new(),
31
24
            alarms: Vec::new(),
32
24
        }
33
24
    }
34

            
35
    pub fn alarms(&self) -> &[CalendarComponent] {
36
        &self.alarms
37
    }
38
}
39

            
40
impl Default for ToDoComponent {
41
    fn default() -> Self {
42
        Self::new()
43
    }
44
}
45

            
46
pub struct ToDoComponentBuilder {
47
    owner: ICalObjectBuilder,
48
    inner: ToDoComponent,
49
}
50

            
51
impl ToDoComponentBuilder {
52
12
    pub(crate) fn new(owner: ICalObjectBuilder) -> Self {
53
12
        ToDoComponentBuilder {
54
12
            owner,
55
12
            inner: ToDoComponent {
56
12
                properties: Vec::new(),
57
12
                alarms: Vec::new(),
58
12
            },
59
12
        }
60
12
    }
61

            
62
    add_date_time_stamp!();
63

            
64
    add_unique_identifier!();
65

            
66
    add_class!();
67

            
68
12
    pub fn add_date_time_completed(
69
12
        self,
70
12
        date: time::Date,
71
12
        time: time::Time,
72
12
    ) -> CompletedPropertyBuilder<Self> {
73
12
        CompletedPropertyBuilder::new(self, date, time)
74
12
    }
75

            
76
    add_created!();
77

            
78
    add_description!();
79

            
80
    add_date_time_start!();
81

            
82
    add_geographic_position!();
83

            
84
    add_last_modified!();
85

            
86
    add_location!();
87

            
88
    add_organizer!();
89

            
90
12
    pub fn add_percent_complete(self, value: u8) -> PercentCompletePropertyBuilder<Self> {
91
12
        PercentCompletePropertyBuilder::new(self, value)
92
12
    }
93

            
94
    add_priority!();
95

            
96
    add_recurrence_id!();
97

            
98
    add_sequence!();
99

            
100
12
    pub fn add_status(self, value: StatusToDo) -> StatusPropertyBuilder<Self> {
101
12
        StatusPropertyBuilder::new(self, value.into())
102
12
    }
103

            
104
    add_summary!();
105

            
106
    add_url!();
107

            
108
    add_recurrence_rule!();
109

            
110
    pub fn add_due_date_time(
111
        self,
112
        date: time::Date,
113
        time: Option<time::Time>,
114
    ) -> DateTimeDuePropertyBuilder<Self> {
115
        DateTimeDuePropertyBuilder::new(self, date, time)
116
    }
117

            
118
    add_duration!();
119

            
120
    add_attach!();
121

            
122
12
    pub fn add_attendee(
123
12
        self,
124
12
        value: &str,
125
12
    ) -> AttendeePropertyBuilder<Self, ParticipationStatusToDo> {
126
12
        AttendeePropertyBuilder::new(self, value.to_string())
127
12
    }
128

            
129
    add_categories!();
130

            
131
    add_comment!();
132

            
133
    add_contact!();
134

            
135
    add_exception_date_times!();
136

            
137
    add_request_status!();
138

            
139
    add_related!();
140

            
141
    add_resources!();
142

            
143
    add_recurrence_date!();
144

            
145
    impl_other_component_properties!(
146
        XComponentPropertyBuilder,
147
        IanaComponentPropertyBuilder,
148
        ToDoComponentBuilder
149
    );
150

            
151
    add_alarms!();
152

            
153
    impl_finish_component_build!(CalendarComponent::ToDo);
154
}
155

            
156
impl AddComponentProperty for ToDoComponentBuilder {
157
384
    fn add_property(&mut self, property: ComponentProperty) {
158
384
        self.inner.properties.push(property);
159
384
    }
160
}
161

            
162
impl AddAlarmComponent for ToDoComponentBuilder {
163
12
    fn add_alarm(mut self, alarm: AlarmComponent) -> Self {
164
12
        self.inner.alarms.push(CalendarComponent::Alarm(alarm));
165
12
        self
166
12
    }
167
}