1
use crate::error::AetoliaResult;
2
use crate::serialize::WriteModel;
3
use std::io::Write;
4

            
5
impl WriteModel for crate::model::component::CalendarComponent {
6
102
    fn write_model<W: Write>(&self, writer: &mut W) -> AetoliaResult<()> {
7
        use crate::model::component::CalendarComponent;
8

            
9
102
        match self {
10
18
            CalendarComponent::Event(component) => {
11
18
                writer.write_all(b"BEGIN:VEVENT")?;
12
140
                for property in &component.properties {
13
122
                    writer.write_all(b"\r\n")?;
14
122
                    property.write_model(writer)?;
15
                }
16
30
                for alarm in &component.alarms {
17
12
                    writer.write_all(b"\r\n")?;
18
12
                    alarm.write_model(writer)?;
19
                }
20
18
                writer.write_all(b"\r\nEND:VEVENT")?;
21
            }
22
6
            CalendarComponent::ToDo(component) => {
23
6
                writer.write_all(b"BEGIN:VTODO")?;
24
100
                for property in &component.properties {
25
94
                    writer.write_all(b"\r\n")?;
26
94
                    property.write_model(writer)?;
27
                }
28
8
                for alarm in &component.alarms {
29
2
                    writer.write_all(b"\r\n")?;
30
2
                    alarm.write_model(writer)?;
31
                }
32
6
                writer.write_all(b"\r\nEND:VTODO")?;
33
            }
34
4
            CalendarComponent::Journal(component) => {
35
4
                writer.write_all(b"BEGIN:VJOURNAL")?;
36
64
                for property in &component.properties {
37
60
                    writer.write_all(b"\r\n")?;
38
60
                    property.write_model(writer)?;
39
                }
40
4
                writer.write_all(b"\r\nEND:VJOURNAL")?;
41
            }
42
8
            CalendarComponent::FreeBusy(component) => {
43
8
                writer.write_all(b"BEGIN:VFREEBUSY")?;
44
78
                for property in &component.properties {
45
70
                    writer.write_all(b"\r\n")?;
46
70
                    property.write_model(writer)?;
47
                }
48
8
                writer.write_all(b"\r\nEND:VFREEBUSY")?;
49
            }
50
12
            CalendarComponent::TimeZone(component) => {
51
12
                writer.write_all(b"BEGIN:VTIMEZONE")?;
52
44
                for property in &component.properties {
53
32
                    writer.write_all(b"\r\n")?;
54
32
                    property.write_model(writer)?;
55
                }
56
48
                for component in &component.components {
57
36
                    writer.write_all(b"\r\n")?;
58
36
                    component.write_model(writer)?;
59
                }
60
12
                writer.write_all(b"\r\nEND:VTIMEZONE")?;
61
            }
62
14
            CalendarComponent::Standard(component) => {
63
14
                writer.write_all(b"BEGIN:STANDARD")?;
64
90
                for property in &component.properties {
65
76
                    writer.write_all(b"\r\n")?;
66
76
                    property.write_model(writer)?;
67
                }
68
14
                writer.write_all(b"\r\nEND:STANDARD")?;
69
            }
70
22
            CalendarComponent::Daylight(component) => {
71
22
                writer.write_all(b"BEGIN:DAYLIGHT")?;
72
138
                for property in &component.properties {
73
116
                    writer.write_all(b"\r\n")?;
74
116
                    property.write_model(writer)?;
75
                }
76
22
                writer.write_all(b"\r\nEND:DAYLIGHT")?;
77
            }
78
14
            CalendarComponent::Alarm(component) => {
79
14
                writer.write_all(b"BEGIN:VALARM")?;
80
108
                for property in &component.properties {
81
94
                    writer.write_all(b"\r\n")?;
82
94
                    property.write_model(writer)?;
83
                }
84
14
                writer.write_all(b"\r\nEND:VALARM")?;
85
            }
86
2
            CalendarComponent::IanaComponent(component) => {
87
2
                writer.write_all(b"BEGIN:")?;
88
2
                writer.write_all(component.name.as_bytes())?;
89
6
                for property in &component.properties {
90
4
                    writer.write_all(b"\r\n")?;
91
4
                    property.write_model(writer)?;
92
                }
93
2
                writer.write_all(b"\r\nEND:")?;
94
2
                writer.write_all(component.name.as_bytes())?;
95
            }
96
2
            CalendarComponent::XComponent(component) => {
97
2
                writer.write_all(b"BEGIN:")?;
98
2
                writer.write_all(component.name.as_bytes())?;
99
6
                for property in &component.properties {
100
4
                    writer.write_all(b"\r\n")?;
101
4
                    property.write_model(writer)?;
102
                }
103
2
                writer.write_all(b"\r\nEND:")?;
104
2
                writer.write_all(component.name.as_bytes())?;
105
            }
106
        }
107

            
108
102
        Ok(())
109
102
    }
110
}