1use crate::DatePerhapsTime;
6use chrono::NaiveDateTime;
7use std::{fmt::Display, str::FromStr};
8
9pub trait Event {
11 fn uid(&self) -> &str;
13 fn summary(&self) -> &str;
15 fn description(&self) -> Option<&str>;
17 fn start(&self) -> Option<DatePerhapsTime>;
19 fn end(&self) -> Option<DatePerhapsTime>;
21 fn status(&self) -> Option<&str>;
23}
24
25#[derive(Debug, Clone, Copy)]
27pub enum EventStatus {
28 Tentative,
29 Confirmed,
30 Cancelled,
31}
32
33const STATUS_TENTATIVE: &str = "TENTATIVE";
34const STATUS_CONFIRMED: &str = "CONFIRMED";
35const STATUS_CANCELLED: &str = "CANCELLED";
36
37impl AsRef<str> for EventStatus {
38 fn as_ref(&self) -> &str {
39 match self {
40 EventStatus::Tentative => STATUS_TENTATIVE,
41 EventStatus::Confirmed => STATUS_CONFIRMED,
42 EventStatus::Cancelled => STATUS_CANCELLED,
43 }
44 }
45}
46
47impl Display for EventStatus {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 write!(f, "{}", self.as_ref())
50 }
51}
52
53impl FromStr for EventStatus {
54 type Err = ();
55
56 fn from_str(value: &str) -> Result<Self, Self::Err> {
57 match value {
58 STATUS_TENTATIVE => Ok(EventStatus::Tentative),
59 STATUS_CONFIRMED => Ok(EventStatus::Confirmed),
60 STATUS_CANCELLED => Ok(EventStatus::Cancelled),
61 _ => Err(()),
62 }
63 }
64}
65
66impl From<EventStatus> for icalendar::EventStatus {
67 fn from(status: EventStatus) -> Self {
68 match status {
69 EventStatus::Tentative => icalendar::EventStatus::Tentative,
70 EventStatus::Confirmed => icalendar::EventStatus::Confirmed,
71 EventStatus::Cancelled => icalendar::EventStatus::Cancelled,
72 }
73 }
74}
75
76impl From<icalendar::EventStatus> for EventStatus {
77 fn from(status: icalendar::EventStatus) -> Self {
78 match status {
79 icalendar::EventStatus::Tentative => EventStatus::Tentative,
80 icalendar::EventStatus::Confirmed => EventStatus::Confirmed,
81 icalendar::EventStatus::Cancelled => EventStatus::Cancelled,
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy)]
88pub struct EventConditions {
89 pub now: NaiveDateTime,
91}