1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! InsightCTA model for Appwrite SDK
use serde::{Deserialize, Serialize};
/// InsightCTA
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(test, derive(Default))]
pub struct InsightCTA {
/// Human-readable label for the CTA, used in UI.
#[serde(rename = "label")]
pub label: String,
/// Public API service (SDK namespace) the client should invoke. Must match the
/// engine that owns the resource — for index suggestions: databases
/// (legacy), tablesDB, documentsDB, or vectorsDB.
#[serde(rename = "service")]
pub service: String,
/// Public API method on the chosen service the client should invoke when this
/// CTA is triggered.
#[serde(rename = "method")]
pub method: String,
/// Parameter map the client should pass to the service method when this CTA is
/// triggered. Keys match the target API's parameter names (e.g.
/// databaseId/tableId/columns for tablesDB, databaseId/collectionId/attributes
/// for the legacy Databases API).
#[serde(rename = "params")]
pub params: serde_json::Value,
}
impl InsightCTA {
/// Get label
pub fn label(&self) -> &String {
&self.label
}
/// Get service
pub fn service(&self) -> &String {
&self.service
}
/// Get method
pub fn method(&self) -> &String {
&self.method
}
/// Get params
pub fn params(&self) -> &serde_json::Value {
&self.params
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_insight_cta_creation() {
let _model = <InsightCTA as Default>::default();
let _ = _model.label();
let _ = _model.service();
let _ = _model.method();
let _ = _model.params();
}
#[test]
fn test_insight_cta_serialization() {
let model = <InsightCTA as Default>::default();
let json = serde_json::to_string(&model);
assert!(json.is_ok());
let deserialized: Result<InsightCTA, _> = serde_json::from_str(&json.unwrap());
assert!(deserialized.is_ok());
}
}