clepsydre-rebind 0.1.0

Safe bindings for libclepsydre
use serde::{Deserialize, Serialize};

/// Calendar creation flows advertised by a collection.
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct CalendarCreationFlows {
    pub flows: Vec<CalendarCreationFlow>,
}

/// A single calendar creation flow.
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct CalendarCreationFlow {
    pub id: String,
    pub title: String,
    pub description: String,
    pub sections: Vec<CalendarCreationSection>,
}

/// A section inside a calendar creation flow.
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct CalendarCreationSection {
    pub title: String,
    pub description: String,
    pub items: Vec<CalendarCreationItem>,
}

/// An item displayed inside a calendar creation section.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum CalendarCreationItem {
    #[serde(rename = "information")]
    Information {
        id: String,
        title: String,
        value: String,
    },
    #[serde(rename = "input")]
    Input { id: String, title: String },
    #[serde(rename = "color")]
    Color { id: String, title: String },
}

impl CalendarCreationItem {
    pub fn id(&self) -> &str {
        match self {
            Self::Information { id, .. } | Self::Input { id, .. } | Self::Color { id, .. } => id,
        }
    }

    pub fn title(&self) -> &str {
        match self {
            Self::Information { title, .. }
            | Self::Input { title, .. }
            | Self::Color { title, .. } => title,
        }
    }
}