use std::sync::Arc;
use crate::auth::models::{GoogleUser, Secret};
use crate::bigquery_api::models::ServiceAccountKey;
use crate::column_types::models::ColumnType;
use crate::sheets_source::constants::GOOGLE_USER;
#[derive(Debug, Clone)]
pub struct SheetsClient {
pub(crate) http: reqwest::Client,
pub(crate) base_url: String,
pub(crate) credential: SheetsCredential,
pub(crate) token: Arc<tokio::sync::Mutex<Option<(Secret, i64)>>>,
}
impl SheetsClient {
pub fn account(&self) -> &str {
match &self.credential {
SheetsCredential::ServiceAccount(key) => &key.client_email,
SheetsCredential::User(_) => GOOGLE_USER,
}
}
}
#[derive(Debug, Clone)]
pub enum SheetsCredential {
ServiceAccount(ServiceAccountKey),
User(Box<GoogleUser>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeySource {
Json(Secret),
Base64(Secret),
File(std::path::PathBuf),
Environment,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NumberKind {
Plain,
Fractional,
Date,
DateTime,
Time,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Cell {
Empty,
Bool(bool),
Number {
value: f64,
kind: NumberKind,
shown: String,
},
Text(String),
Error(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Grid {
pub title: String,
pub start_row: u32,
pub start_column: u32,
pub rows: Vec<Vec<Cell>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HeaderRule {
pub header: bool,
pub header_row: u32,
pub column_names: Option<Vec<String>>,
pub width: Option<usize>,
}
impl Default for HeaderRule {
fn default() -> Self {
Self {
header: true,
header_row: 1,
column_names: None,
width: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SheetRead {
pub range: Option<String>,
pub rule: HeaderRule,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SheetColumn {
pub name: String,
pub position: usize,
pub column_type: Result<ColumnType, String>,
pub has_values: bool,
pub repeat_of: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SheetTable {
pub columns: Vec<SheetColumn>,
pub rows: usize,
pub warnings: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct A1Range {
pub sheet: Option<String>,
pub first_column: u32,
pub last_column: u32,
pub first_row: u32,
pub last_row: Option<u32>,
}
impl A1Range {
pub fn width(&self) -> usize {
(self.last_column - self.first_column) as usize + 1
}
}