use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Document {
pub document_id: String,
pub title: String,
pub body: Option<Body>,
pub revision_id: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Body {
pub content: Option<Vec<StructuralElement>>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StructuralElement {
pub start_index: Option<i32>,
pub end_index: Option<i32>,
pub paragraph: Option<Paragraph>,
pub table: Option<Table>,
pub section_break: Option<SectionBreak>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Paragraph {
pub elements: Vec<ParagraphElement>,
pub paragraph_style: Option<ParagraphStyle>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphElement {
pub start_index: Option<i32>,
pub end_index: Option<i32>,
pub text_run: Option<TextRun>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TextRun {
pub content: String,
pub text_style: Option<TextStyle>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TextStyle {
#[serde(skip_serializing_if = "Option::is_none")]
pub bold: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub italic: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub underline: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub strikethrough: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_size: Option<Dimension>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dimension {
pub magnitude: f64,
pub unit: String,
}
impl Dimension {
pub fn pt(magnitude: f64) -> Self {
Self {
magnitude,
unit: "PT".to_string(),
}
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphStyle {
pub named_style_type: Option<String>,
pub alignment: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Table {
pub rows: i32,
pub columns: i32,
pub table_rows: Vec<TableRow>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TableRow {
pub table_cells: Vec<TableCell>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TableCell {
pub content: Vec<StructuralElement>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SectionBreak {
pub section_style: Option<SectionStyle>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SectionStyle {
pub section_type: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchUpdateRequest {
pub requests: Vec<Request>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Request {
#[serde(skip_serializing_if = "Option::is_none")]
pub insert_text: Option<InsertTextRequest>,
#[serde(skip_serializing_if = "Option::is_none")]
pub delete_content_range: Option<DeleteContentRangeRequest>,
#[serde(skip_serializing_if = "Option::is_none")]
pub update_text_style: Option<UpdateTextStyleRequest>,
}
impl Request {
pub fn insert_text(text: impl Into<String>, index: i32) -> Self {
Self {
insert_text: Some(InsertTextRequest {
text: text.into(),
location: Location { index },
}),
delete_content_range: None,
update_text_style: None,
}
}
pub fn delete_range(start: i32, end: i32) -> Self {
Self {
insert_text: None,
delete_content_range: Some(DeleteContentRangeRequest {
range: Range {
start_index: start,
end_index: end,
},
}),
update_text_style: None,
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InsertTextRequest {
pub text: String,
pub location: Location,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Location {
pub index: i32,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteContentRangeRequest {
pub range: Range,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Range {
pub start_index: i32,
pub end_index: i32,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateTextStyleRequest {
pub range: Range,
pub text_style: TextStyle,
pub fields: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchUpdateResponse {
pub document_id: String,
pub replies: Vec<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateDocumentRequest {
pub title: String,
}
impl CreateDocumentRequest {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
}
}
}