1
use crate::model::component::{
2
    add_action, add_attach, add_description, add_duration, add_repeat, add_summary, add_trigger,
3
    impl_other_component_properties,
4
};
5
use crate::model::impl_component_access;
6
use crate::model::param::ParticipationStatusEvent;
7
use crate::model::property::{
8
    Action, AddComponentProperty, AttendeePropertyBuilder, ComponentProperty,
9
    IanaComponentPropertyBuilder, XComponentPropertyBuilder,
10
};
11

            
12
#[derive(Debug, PartialEq)]
13
pub struct AlarmComponent {
14
    pub(crate) properties: Vec<ComponentProperty>,
15
}
16

            
17
impl_component_access!(AlarmComponent);
18

            
19
impl AlarmComponent {
20
62
    pub(crate) fn new() -> Self {
21
62
        AlarmComponent {
22
62
            properties: Vec::new(),
23
62
        }
24
62
    }
25
}
26

            
27
impl Default for AlarmComponent {
28
    fn default() -> Self {
29
        Self::new()
30
    }
31
}
32

            
33
pub trait AddAlarmComponent {
34
    fn add_alarm(self, alarm: AlarmComponent) -> Self;
35
}
36

            
37
pub struct AudioAlarmComponentBuilder<P: AddAlarmComponent> {
38
    owner: P,
39
    inner: AlarmComponent,
40
}
41

            
42
impl<P> AudioAlarmComponentBuilder<P>
43
where
44
    P: AddAlarmComponent,
45
{
46
12
    pub(crate) fn new(owner: P) -> Self {
47
12
        AudioAlarmComponentBuilder {
48
12
            owner,
49
12
            inner: AlarmComponent {
50
12
                properties: Vec::new(),
51
12
            },
52
12
        }
53
12
    }
54

            
55
    add_action!(Action::Audio);
56

            
57
    add_trigger!();
58

            
59
    add_duration!();
60

            
61
    add_repeat!();
62

            
63
    add_attach!();
64

            
65
    impl_other_component_properties!(
66
        XComponentPropertyBuilder,
67
        IanaComponentPropertyBuilder,
68
        AudioAlarmComponentBuilder<P>
69
    );
70

            
71
4
    pub fn finish_component(self) -> P {
72
4
        self.owner.add_alarm(self.inner)
73
4
    }
74
}
75

            
76
impl<P> AddComponentProperty for AudioAlarmComponentBuilder<P>
77
where
78
    P: AddAlarmComponent,
79
{
80
28
    fn add_property(&mut self, property: ComponentProperty) {
81
28
        self.inner.properties.push(property);
82
28
    }
83
}
84

            
85
pub struct DisplayAlarmComponentBuilder<P: AddAlarmComponent> {
86
    owner: P,
87
    inner: AlarmComponent,
88
}
89

            
90
impl<P> DisplayAlarmComponentBuilder<P>
91
where
92
    P: AddAlarmComponent,
93
{
94
24
    pub(crate) fn new(owner: P) -> Self {
95
24
        DisplayAlarmComponentBuilder {
96
24
            owner,
97
24
            inner: AlarmComponent {
98
24
                properties: Vec::new(),
99
24
            },
100
24
        }
101
24
    }
102

            
103
    add_action!(Action::Display);
104

            
105
    add_description!();
106

            
107
    add_trigger!();
108

            
109
    add_duration!();
110

            
111
    add_repeat!();
112

            
113
    impl_other_component_properties!(
114
        XComponentPropertyBuilder,
115
        IanaComponentPropertyBuilder,
116
        DisplayAlarmComponentBuilder<P>
117
    );
118

            
119
8
    pub fn finish_component(self) -> P {
120
8
        self.owner.add_alarm(self.inner)
121
8
    }
122
}
123

            
124
impl<P> AddComponentProperty for DisplayAlarmComponentBuilder<P>
125
where
126
    P: AddAlarmComponent,
127
{
128
56
    fn add_property(&mut self, property: ComponentProperty) {
129
56
        self.inner.properties.push(property);
130
56
    }
131
}
132

            
133
pub struct EmailAlarmComponentBuilder<P: AddAlarmComponent> {
134
    owner: P,
135
    inner: AlarmComponent,
136
}
137

            
138
impl<P> EmailAlarmComponentBuilder<P>
139
where
140
    P: AddAlarmComponent,
141
{
142
12
    pub(crate) fn new(owner: P) -> Self {
143
12
        EmailAlarmComponentBuilder {
144
12
            owner,
145
12
            inner: AlarmComponent {
146
12
                properties: Vec::new(),
147
12
            },
148
12
        }
149
12
    }
150

            
151
    add_action!(Action::Email);
152

            
153
    add_description!();
154

            
155
    add_trigger!();
156

            
157
    add_summary!();
158

            
159
4
    pub fn add_attendee(
160
4
        self,
161
4
        value: &str,
162
4
    ) -> AttendeePropertyBuilder<Self, ParticipationStatusEvent> {
163
4
        AttendeePropertyBuilder::new(self, value.to_string())
164
4
    }
165

            
166
    add_duration!();
167

            
168
    add_repeat!();
169

            
170
    add_attach!();
171

            
172
    impl_other_component_properties!(
173
        XComponentPropertyBuilder,
174
        IanaComponentPropertyBuilder,
175
        EmailAlarmComponentBuilder<P>
176
    );
177

            
178
4
    pub fn finish_component(self) -> P {
179
4
        self.owner.add_alarm(self.inner)
180
4
    }
181
}
182

            
183
impl<P> AddComponentProperty for EmailAlarmComponentBuilder<P>
184
where
185
    P: AddAlarmComponent,
186
{
187
40
    fn add_property(&mut self, property: ComponentProperty) {
188
40
        self.inner.properties.push(property);
189
40
    }
190
}