use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::core::api_resp::{ApiResponseTrait, ResponseFormat};
#[derive(Serialize, Debug, Default)]
pub(crate) struct ValueRangeRequest {
pub(crate) range: String,
pub(crate) values: Value,
}
#[derive(Deserialize, Debug, Default)]
#[allow(dead_code)]
pub struct ValueRangeResponse {
#[serde(rename = "majorDimension")]
pub major_dimension: String,
pub range: String,
pub values: Value,
pub revision: i32,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct UpdateSheetDataResponse {
#[serde(rename = "spreadsheetToken")]
pub spreed_sheet_token: String,
#[serde(rename = "tableRange")]
pub table_range: String,
pub revision: i32,
pub updates: SheetDataUpdates,
}
impl ApiResponseTrait for UpdateSheetDataResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct SheetDataUpdates {
#[serde(rename = "spreadsheetToken")]
pub spreed_sheet_token: String,
#[serde(rename = "updatedRange")]
pub updated_range: String,
#[serde(rename = "updatedRows")]
pub updated_rows: i32,
#[serde(rename = "updatedColumns")]
pub updated_columns: i32,
#[serde(rename = "updatedCells")]
pub updated_cells: i32,
pub revision: Option<i32>,
}
impl ApiResponseTrait for SheetDataUpdates {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct ReadRangeValueRange {
#[serde(rename = "majorDimension")]
pub major_dimension: String,
pub range: String,
pub revision: i32,
pub values: Value,
}
#[derive(Debug, Serialize, Default)]
pub struct CellStyle {
pub(crate) font: StyleFont,
#[serde(rename = "textDecoration")]
pub(crate) text_decoration: Option<i32>,
pub(crate) formatter: Option<String>,
#[serde(rename = "hAlign")]
pub(crate) h_align: Option<i32>,
#[serde(rename = "vAlign")]
pub(crate) v_align: Option<i32>,
#[serde(rename = "foreColor")]
pub(crate) fore_color: Option<String>,
#[serde(rename = "backColor")]
pub(crate) back_color: Option<String>,
#[serde(rename = "borderType")]
pub(crate) border_type: Option<String>,
#[serde(rename = "borderColor")]
pub(crate) border_color: Option<String>,
pub(crate) clean: bool,
}
impl CellStyle {
pub fn builder() -> CellStyleBuilder {
CellStyleBuilder::default()
}
}
#[derive(Default)]
pub struct CellStyleBuilder {
request: CellStyle,
}
impl CellStyleBuilder {
pub fn font(mut self, font: StyleFont) -> Self {
self.request.font = font;
self
}
pub fn text_decoration(mut self, text_decoration: i32) -> Self {
self.request.text_decoration = Some(text_decoration);
self
}
pub fn formatter(mut self, formatter: impl ToString) -> Self {
self.request.formatter = Some(formatter.to_string());
self
}
pub fn h_align(mut self, h_align: i32) -> Self {
self.request.h_align = Some(h_align);
self
}
pub fn v_align(mut self, v_align: i32) -> Self {
self.request.v_align = Some(v_align);
self
}
pub fn fore_color(mut self, fore_color: impl ToString) -> Self {
self.request.fore_color = Some(fore_color.to_string());
self
}
pub fn back_color(mut self, back_color: impl ToString) -> Self {
self.request.back_color = Some(back_color.to_string());
self
}
pub fn border_type(mut self, border_type: impl ToString) -> Self {
self.request.border_type = Some(border_type.to_string());
self
}
pub fn border_color(mut self, border_color: impl ToString) -> Self {
self.request.border_color = Some(border_color.to_string());
self
}
pub fn clean(mut self, clean: bool) -> Self {
self.request.clean = clean;
self
}
pub fn build(self) -> CellStyle {
self.request
}
}
#[derive(Debug, Serialize, Default)]
pub struct StyleFont {
bold: Option<bool>,
italic: Option<bool>,
#[serde(rename = "fontSize")]
font_size: Option<String>,
clean: Option<bool>,
}
impl StyleFont {
pub fn builder() -> StyleFontBuilder {
StyleFontBuilder::default()
}
}
#[derive(Default)]
pub struct StyleFontBuilder {
font: StyleFont,
}
impl StyleFontBuilder {
pub fn bold(mut self, bold: bool) -> Self {
self.font.bold = Some(bold);
self
}
pub fn italic(mut self, italic: bool) -> Self {
self.font.italic = Some(italic);
self
}
pub fn font_size(mut self, font_size: impl ToString) -> Self {
self.font.font_size = Some(font_size.to_string());
self
}
pub fn clean(mut self, clean: bool) -> Self {
self.font.clean = Some(clean);
self
}
pub fn build(self) -> StyleFont {
self.font
}
}