1
use crate::model::component::daylight::DaylightComponentBuilder;
2
use crate::model::component::standard::StandardComponentBuilder;
3
use crate::model::component::{
4
    add_last_modified, impl_finish_component_build, impl_other_component_properties,
5
    CalendarComponent, ComponentProperty,
6
};
7
use crate::model::impl_component_access;
8
use crate::model::object::ICalObjectBuilder;
9
use crate::model::property::{
10
    AddComponentProperty, IanaComponentPropertyBuilder, TimeZoneIdPropertyBuilder,
11
    TimeZoneUrlPropertyBuilder, XComponentPropertyBuilder,
12
};
13

            
14
#[derive(Debug, PartialEq)]
15
pub struct TimeZoneComponent {
16
    pub(crate) properties: Vec<ComponentProperty>,
17
    pub(crate) components: Vec<CalendarComponent>,
18
}
19

            
20
impl_component_access!(TimeZoneComponent);
21

            
22
impl TimeZoneComponent {
23
38
    pub(crate) fn new() -> Self {
24
38
        TimeZoneComponent {
25
38
            properties: Vec::new(),
26
38
            components: Vec::new(),
27
38
        }
28
38
    }
29

            
30
6
    pub fn nested_components(&self) -> &[CalendarComponent] {
31
6
        &self.components
32
6
    }
33
}
34

            
35
impl Default for TimeZoneComponent {
36
    fn default() -> Self {
37
        Self::new()
38
    }
39
}
40

            
41
pub struct TimeZoneComponentBuilder {
42
    owner: ICalObjectBuilder,
43
    pub(crate) inner: TimeZoneComponent,
44
}
45

            
46
impl TimeZoneComponentBuilder {
47
12
    pub(crate) fn new(owner: ICalObjectBuilder) -> Self {
48
12
        TimeZoneComponentBuilder {
49
12
            owner,
50
12
            inner: TimeZoneComponent {
51
12
                properties: Vec::new(),
52
12
                components: Vec::new(),
53
12
            },
54
12
        }
55
12
    }
56

            
57
12
    pub fn add_time_zone_id(
58
12
        self,
59
12
        value: &str,
60
12
        unique_registry_id: bool,
61
12
    ) -> TimeZoneIdPropertyBuilder<Self> {
62
12
        TimeZoneIdPropertyBuilder::new(self, value.to_string(), unique_registry_id)
63
12
    }
64

            
65
    add_last_modified!();
66

            
67
12
    pub fn add_time_zone_url(self, value: &str) -> TimeZoneUrlPropertyBuilder<Self> {
68
12
        TimeZoneUrlPropertyBuilder::new(self, value.to_string())
69
12
    }
70

            
71
12
    pub fn add_standard_time(
72
12
        self,
73
12
        builder: fn(StandardComponentBuilder) -> StandardComponentBuilder,
74
12
    ) -> Self {
75
12
        builder(StandardComponentBuilder::new(self)).build()
76
12
    }
77

            
78
12
    pub fn add_daylight_time(
79
12
        self,
80
12
        builder: fn(DaylightComponentBuilder) -> DaylightComponentBuilder,
81
12
    ) -> Self {
82
12
        builder(DaylightComponentBuilder::new(self)).build()
83
12
    }
84

            
85
    impl_other_component_properties!(
86
        XComponentPropertyBuilder,
87
        IanaComponentPropertyBuilder,
88
        TimeZoneComponentBuilder
89
    );
90

            
91
    impl_finish_component_build!(CalendarComponent::TimeZone);
92
}
93

            
94
impl AddComponentProperty for TimeZoneComponentBuilder {
95
60
    fn add_property(&mut self, property: ComponentProperty) {
96
60
        self.inner.properties.push(property);
97
60
    }
98
}