car-integrations 0.6.0

OS-native account-bound integrations (Calendar, Contacts, Mail) for CAR
Documentation
//! Calendar capability — list calendars, list upcoming events.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use super::{Availability, IntegrationError};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Calendar {
    /// Stable identifier within the current host.
    pub id: String,
    /// Display name as shown in the user's Calendar app.
    pub title: String,
    /// Source label (account / provider) where the OS exposes it.
    pub source: Option<String>,
    /// Calendar color as `#RRGGBB` hex, when available.
    pub color: Option<String>,
    /// Whether the user can create/update events on this calendar.
    pub writable: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Event {
    pub id: String,
    pub calendar_id: String,
    pub title: String,
    pub start: DateTime<Utc>,
    pub end: DateTime<Utc>,
    #[serde(default)]
    pub all_day: bool,
    pub location: Option<String>,
    pub notes: Option<String>,
    #[serde(default)]
    pub attendees: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CalendarListing {
    #[serde(flatten)]
    pub availability: Availability,
    pub calendars: Vec<Calendar>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventListing {
    #[serde(flatten)]
    pub availability: Availability,
    pub events: Vec<Event>,
}

pub fn list_calendars() -> Result<CalendarListing, IntegrationError> {
    Ok(CalendarListing {
        availability: current_backend_pending(),
        calendars: vec![],
    })
}

/// List events between `start` and `end`. When no calendar IDs are
/// supplied, backends include all accessible calendars.
pub fn list_events(
    _start: DateTime<Utc>,
    _end: DateTime<Utc>,
    _calendar_ids: &[String],
) -> Result<EventListing, IntegrationError> {
    Ok(EventListing {
        availability: current_backend_pending(),
        events: vec![],
    })
}

fn current_backend_pending() -> Availability {
    #[cfg(target_os = "macos")]
    {
        Availability::pending(
            "eventkit",
            "EventKit backend not yet wired. API shape is stable; \
             downstream apps can code against it now.",
        )
    }
    #[cfg(target_os = "windows")]
    {
        Availability::pending(
            "msgraph",
            "MS Graph / Outlook MAPI backends not yet wired. API shape \
             is stable; downstream apps can code against it now.",
        )
    }
    #[cfg(target_os = "linux")]
    {
        Availability::pending(
            "eds",
            "Evolution Data Server + CalDAV backends not yet wired. \
             API shape is stable; downstream apps can code against it now.",
        )
    }
    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
    {
        Availability::pending("none", "Unsupported OS — no calendar backend modeled.")
    }
}