use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Status {
Success,
Error,
}
#[derive(Debug, Serialize)]
pub struct ToolResponse<T: Serialize> {
pub status: Status,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<T>,
}
#[derive(Debug, Serialize)]
pub struct ErrorData {
pub category: ErrorCategory,
pub description: String,
pub suggestion: String,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ErrorCategory {
NotFound,
InvalidInput,
EngineUnsupported,
CapacityExceeded,
IoError,
ParseError,
Evicted,
}
pub fn success<T: Serialize>(message: &str, data: T) -> String {
serde_json::to_string(&ToolResponse {
status: Status::Success,
message: message.to_string(),
data: Some(data),
})
.expect("serialization of ToolResponse should never fail")
}
pub fn success_no_data(message: &str) -> String {
serde_json::to_string(&ToolResponse::<()> {
status: Status::Success,
message: message.to_string(),
data: None,
})
.expect("serialization of ToolResponse should never fail")
}
pub fn error(category: ErrorCategory, description: &str, suggestion: &str) -> String {
serde_json::to_string(&ToolResponse {
status: Status::Error,
message: description.to_string(),
data: Some(ErrorData {
category,
description: description.to_string(),
suggestion: suggestion.to_string(),
}),
})
.expect("serialization of ToolResponse should never fail")
}
#[derive(Debug, Serialize)]
pub struct WorkbookInfo {
pub workbook_id: String,
pub engine: String,
pub sheets: Vec<SheetSummary>,
}
#[derive(Debug, Serialize)]
pub struct SheetSummary {
pub name: String,
pub dimensions: Option<String>,
pub row_count: Option<u32>,
pub col_count: Option<u16>,
}
#[derive(Debug, Serialize)]
pub struct ReadSheetData {
pub rows: Vec<Vec<serde_json::Value>>,
pub total_rows: u32,
pub page_rows: u32,
pub continuation_token: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct CellData {
pub cell: String,
pub value: serde_json::Value,
pub value_type: String,
pub formula: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct WriteResult {
pub cells_written: usize,
pub range_covered: String,
}
#[derive(Debug, Serialize)]
pub struct SearchResult {
pub matches: Vec<SearchMatch>,
pub total_matches: usize,
pub truncated: bool,
}
#[derive(Debug, Serialize)]
pub struct SearchMatch {
pub sheet: String,
pub cell: String,
pub value: serde_json::Value,
}
#[derive(Debug, Serialize)]
pub struct WorkbookDescription {
pub workbook_id: String,
pub engine: String,
pub sheets: Vec<SheetDescription>,
}
#[derive(Debug, Serialize)]
pub struct SheetDescription {
pub name: String,
pub dimensions: Option<String>,
pub row_count: Option<u32>,
pub col_count: Option<u16>,
pub sample_rows: Vec<Vec<serde_json::Value>>,
}
#[derive(Debug, Serialize)]
pub struct CsvExportData {
pub csv: String,
pub total_rows: u32,
pub truncated: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ContinuationToken {
pub sheet: String,
pub offset: u32,
pub range: Option<String>,
}