use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Presentation {
pub presentation_id: String,
pub title: Option<String>,
pub revision_id: Option<String>,
pub page_size: Option<serde_json::Value>,
pub slides: Vec<Page>,
pub layouts: Vec<Page>,
pub masters: Vec<Page>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Page {
pub object_id: String,
pub page_type: Option<String>,
pub page_elements: Vec<PageElement>,
pub slide_properties: Option<SlideProperties>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct SlideProperties {
pub notes_page: Option<Box<Page>>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct PageElement {
pub object_id: String,
pub shape: Option<Shape>,
pub table: Option<Table>,
pub image: Option<serde_json::Value>,
pub element_group: Option<ElementGroup>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default)]
pub struct ElementGroup {
pub children: Vec<PageElement>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default)]
pub struct Shape {
pub text: Option<Text>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Text {
pub text_elements: Vec<TextElement>,
}
impl Text {
pub fn content(&self) -> String {
self.text_elements
.iter()
.filter_map(|e| e.text_run.as_ref())
.map(|r| r.content.as_str())
.collect()
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct TextElement {
pub text_run: Option<TextRun>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default)]
pub struct TextRun {
pub content: String,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Table {
pub table_rows: Vec<TableRow>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct TableRow {
pub table_cells: Vec<TableCell>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, rename_all = "camelCase")]
pub struct TableCell {
pub text: Option<Text>,
pub location: Option<CellLocation>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
#[serde(default, rename_all = "camelCase")]
pub struct CellLocation {
pub row_index: usize,
pub column_index: usize,
}