Skip to main content

car_integrations/calendar/
mod.rs

1//! Calendar capability — list calendars, list upcoming events.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use super::{Availability, IntegrationError};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Calendar {
10    /// Stable identifier within the current host.
11    pub id: String,
12    /// Display name as shown in the user's Calendar app.
13    pub title: String,
14    /// Source label (account / provider) where the OS exposes it.
15    pub source: Option<String>,
16    /// Calendar color as `#RRGGBB` hex, when available.
17    pub color: Option<String>,
18    /// Whether the user can create/update events on this calendar.
19    pub writable: bool,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct Event {
24    pub id: String,
25    pub calendar_id: String,
26    pub title: String,
27    pub start: DateTime<Utc>,
28    pub end: DateTime<Utc>,
29    #[serde(default)]
30    pub all_day: bool,
31    pub location: Option<String>,
32    pub notes: Option<String>,
33    #[serde(default)]
34    pub attendees: Vec<String>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct CalendarListing {
39    #[serde(flatten)]
40    pub availability: Availability,
41    pub calendars: Vec<Calendar>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct EventListing {
46    #[serde(flatten)]
47    pub availability: Availability,
48    pub events: Vec<Event>,
49}
50
51pub fn list_calendars() -> Result<CalendarListing, IntegrationError> {
52    Ok(CalendarListing {
53        availability: current_backend_pending(),
54        calendars: vec![],
55    })
56}
57
58/// List events between `start` and `end`. When no calendar IDs are
59/// supplied, backends include all accessible calendars.
60pub fn list_events(
61    _start: DateTime<Utc>,
62    _end: DateTime<Utc>,
63    _calendar_ids: &[String],
64) -> Result<EventListing, IntegrationError> {
65    Ok(EventListing {
66        availability: current_backend_pending(),
67        events: vec![],
68    })
69}
70
71fn current_backend_pending() -> Availability {
72    #[cfg(target_os = "macos")]
73    {
74        Availability::pending(
75            "eventkit",
76            "EventKit backend not yet wired. API shape is stable; \
77             downstream apps can code against it now.",
78        )
79    }
80    #[cfg(target_os = "windows")]
81    {
82        Availability::pending(
83            "msgraph",
84            "MS Graph / Outlook MAPI backends not yet wired. API shape \
85             is stable; downstream apps can code against it now.",
86        )
87    }
88    #[cfg(target_os = "linux")]
89    {
90        Availability::pending(
91            "eds",
92            "Evolution Data Server + CalDAV backends not yet wired. \
93             API shape is stable; downstream apps can code against it now.",
94        )
95    }
96    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
97    {
98        Availability::pending("none", "Unsupported OS — no calendar backend modeled.")
99    }
100}