1
use crate::model::component::CalendarComponent;
2
use crate::model::component::IanaComponentBuilder;
3
use crate::model::component::XComponentBuilder;
4
use crate::model::component::{
5
    EventComponentBuilder, FreeBusyComponentBuilder, JournalComponentBuilder,
6
    TimeZoneComponentBuilder, ToDoComponentBuilder,
7
};
8
use crate::model::property::{
9
    CalendarProperty, CalendarScalePropertyBuilder, IanaPropertyBuilder, MethodPropertyBuilder,
10
    ProductIdPropertyBuilder, VersionPropertyBuilder, XPropertyBuilder,
11
};
12

            
13
#[derive(Debug, PartialEq)]
14
pub struct ICalObject {
15
    pub properties: Vec<CalendarProperty>,
16
    pub components: Vec<CalendarComponent>,
17
}
18

            
19
impl ICalObject {
20
22
    pub fn builder() -> ICalObjectBuilder {
21
22
        ICalObjectBuilder {
22
22
            inner: ICalObject::new(),
23
22
        }
24
22
    }
25

            
26
244
    pub(crate) fn new() -> ICalObject {
27
244
        ICalObject {
28
244
            properties: Vec::new(),
29
244
            components: Vec::new(),
30
244
        }
31
244
    }
32
}
33

            
34
pub struct ICalObjectBuilder {
35
    pub(crate) inner: ICalObject,
36
}
37

            
38
impl ICalObjectBuilder {
39
14
    pub fn add_product_id<V: ToString>(self, value: V) -> ProductIdPropertyBuilder {
40
14
        ProductIdPropertyBuilder::new(self, value.to_string())
41
14
    }
42

            
43
    pub fn add_version_range<U: ToString, V: ToString>(
44
        self,
45
        min_version: U,
46
        max_version: V,
47
    ) -> VersionPropertyBuilder {
48
        VersionPropertyBuilder::new(self, Some(min_version.to_string()), max_version.to_string())
49
    }
50

            
51
10
    pub fn add_max_version<V: ToString>(self, max_version: V) -> VersionPropertyBuilder {
52
10
        VersionPropertyBuilder::new(self, None, max_version.to_string())
53
10
    }
54

            
55
6
    pub fn add_calendar_scale<V: ToString>(self, value: V) -> CalendarScalePropertyBuilder {
56
6
        CalendarScalePropertyBuilder::new(self, value.to_string())
57
6
    }
58

            
59
6
    pub fn add_method<V: ToString>(self, value: V) -> MethodPropertyBuilder {
60
6
        MethodPropertyBuilder::new(self, value.to_string())
61
6
    }
62

            
63
2
    pub fn add_x_property<N: ToString, V: ToString>(self, name: N, value: V) -> XPropertyBuilder {
64
2
        XPropertyBuilder::new(self, name.to_string(), value.to_string())
65
2
    }
66

            
67
2
    pub fn add_iana_property<N: ToString, V: ToString>(
68
2
        self,
69
2
        name: N,
70
2
        value: V,
71
2
    ) -> IanaPropertyBuilder {
72
2
        IanaPropertyBuilder::new(self, name.to_string(), value.to_string())
73
2
    }
74

            
75
14
    pub fn add_event_component(self) -> EventComponentBuilder {
76
14
        EventComponentBuilder::new(self)
77
14
    }
78

            
79
12
    pub fn add_to_do_component(self) -> ToDoComponentBuilder {
80
12
        ToDoComponentBuilder::new(self)
81
12
    }
82

            
83
14
    pub fn add_journal_component(self) -> JournalComponentBuilder {
84
14
        JournalComponentBuilder::new(self)
85
14
    }
86

            
87
12
    pub fn add_free_busy_component(self) -> FreeBusyComponentBuilder {
88
12
        FreeBusyComponentBuilder::new(self)
89
12
    }
90

            
91
12
    pub fn add_time_zone_component(self) -> TimeZoneComponentBuilder {
92
12
        TimeZoneComponentBuilder::new(self)
93
12
    }
94

            
95
6
    pub fn add_iana_component<N: ToString>(
96
6
        self,
97
6
        name: N,
98
6
        builder: fn(IanaComponentBuilder) -> IanaComponentBuilder,
99
6
    ) -> Self {
100
6
        builder(IanaComponentBuilder::new(self, name.to_string())).finish_component()
101
6
    }
102

            
103
6
    pub fn add_x_component<N: ToString>(
104
6
        self,
105
6
        name: N,
106
6
        builder: fn(XComponentBuilder) -> XComponentBuilder,
107
6
    ) -> Self {
108
6
        builder(XComponentBuilder::new(self, name.to_string())).finish_component()
109
6
    }
110

            
111
22
    pub fn build(self) -> ICalObject {
112
22
        self.inner
113
22
    }
114
}