use jmap_types::{GetObject, JmapObject, PatchObject, QueryObject, SetObject};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CalendarProperty {
Id,
Name,
Description,
Color,
SortOrder,
IsSubscribed,
IsVisible,
IsDefault,
IncludeInAvailability,
DefaultAlertsWithTime,
DefaultAlertsWithoutTime,
TimeZone,
ShareWith,
MyRights,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CalendarEventProperty {
Id,
BaseEventId,
CalendarIds,
IsDraft,
IsOrigin,
UtcStart,
UtcEnd,
UseDefaultAlerts,
MayInviteSelf,
MayInviteOthers,
HideAttendees,
BlobId,
Uid,
Title,
Description,
Start,
Duration,
Status,
}
pub const PER_USER_CALENDAR_EVENT_PROPERTIES: &[&str] = &[
"keywords",
"color",
"freeBusyStatus",
"useDefaultAlerts",
"alerts",
];
#[must_use]
pub fn is_per_user_calendar_event_property(name: &str) -> bool {
PER_USER_CALENDAR_EVENT_PROPERTIES.contains(&name)
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CalendarEventNotificationProperty {
Id,
Created,
ChangedBy,
Comment,
Type,
CalendarEventId,
IsDraft,
Event,
EventPatch,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ParticipantIdentityProperty {
Id,
Name,
CalendarAddress,
IsDefault,
}
impl JmapObject for crate::Calendar {
const TYPE_NAME: &'static str = "Calendar";
type Property = CalendarProperty;
}
impl GetObject for crate::Calendar {}
impl SetObject for crate::Calendar {
type Patch = PatchObject;
}
impl QueryObject for crate::Calendar {
type Filter = crate::CalendarFilterCondition;
type Comparator = serde_json::Value;
}
impl JmapObject for crate::CalendarEvent {
const TYPE_NAME: &'static str = "CalendarEvent";
type Property = CalendarEventProperty;
}
impl GetObject for crate::CalendarEvent {}
impl SetObject for crate::CalendarEvent {
type Patch = PatchObject;
}
impl QueryObject for crate::CalendarEvent {
type Filter = crate::CalendarEventFilterCondition;
type Comparator = crate::CalendarEventComparator;
}
impl JmapObject for crate::CalendarEventNotification {
const TYPE_NAME: &'static str = "CalendarEventNotification";
type Property = CalendarEventNotificationProperty;
}
impl GetObject for crate::CalendarEventNotification {}
impl SetObject for crate::CalendarEventNotification {
type Patch = PatchObject;
}
impl QueryObject for crate::CalendarEventNotification {
type Filter = crate::NotificationFilterCondition;
type Comparator = serde_json::Value;
}
impl JmapObject for crate::ParticipantIdentity {
const TYPE_NAME: &'static str = "ParticipantIdentity";
type Property = ParticipantIdentityProperty;
}
impl GetObject for crate::ParticipantIdentity {}
impl SetObject for crate::ParticipantIdentity {
type Patch = PatchObject;
}
impl QueryObject for crate::ParticipantIdentity {
type Filter = serde_json::Value;
type Comparator = serde_json::Value;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn per_user_calendar_event_properties_match_spec() {
assert_eq!(
PER_USER_CALENDAR_EVENT_PROPERTIES,
&[
"keywords",
"color",
"freeBusyStatus",
"useDefaultAlerts",
"alerts"
]
);
}
#[test]
fn is_per_user_classifies_spec_properties_as_true() {
for name in PER_USER_CALENDAR_EVENT_PROPERTIES {
assert!(
is_per_user_calendar_event_property(name),
"expected {name} to be classified per-user"
);
}
}
#[test]
fn is_per_user_classifies_shared_properties_as_false() {
for shared in &["id", "title", "start", "duration", "calendarIds", "uid"] {
assert!(
!is_per_user_calendar_event_property(shared),
"expected {shared} to be classified shared"
);
}
}
#[test]
fn is_per_user_rejects_unknown_property() {
assert!(!is_per_user_calendar_event_property(""));
assert!(!is_per_user_calendar_event_property("notARealProperty"));
assert!(!is_per_user_calendar_event_property("alerts/abc"));
}
}