1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct ModelInfo {
10 pub name: String,
12 #[serde(rename = "id")]
14 pub model_id: i64,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct ModelField {
20 pub name: String,
22 #[serde(default)]
24 pub ord: i32,
25 #[serde(default)]
27 pub sticky: bool,
28 #[serde(default)]
30 pub rtl: bool,
31 #[serde(default)]
33 pub font: String,
34 #[serde(default)]
36 pub size: i32,
37 #[serde(default)]
39 pub description: String,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct CardTemplate {
48 #[serde(rename = "Front")]
50 pub front: String,
51 #[serde(rename = "Back")]
53 pub back: String,
54}
55
56#[derive(Debug, Clone, Serialize)]
58pub struct CreateCardTemplate {
59 #[serde(rename = "Name")]
61 pub name: String,
62 #[serde(rename = "Front")]
64 pub front: String,
65 #[serde(rename = "Back")]
67 pub back: String,
68}
69
70#[derive(Debug, Clone, Deserialize)]
72pub struct FieldFont {
73 pub font: String,
75 pub size: i32,
77}
78
79#[derive(Debug, Clone, Serialize)]
81#[serde(rename_all = "camelCase")]
82pub struct CreateModelParams {
83 pub model_name: String,
85 pub in_order_fields: Vec<String>,
87 pub css: String,
89 #[serde(skip_serializing_if = "Option::is_none")]
91 pub is_cloze: Option<bool>,
92 pub card_templates: Vec<CreateCardTemplate>,
94}
95
96impl CreateModelParams {
97 pub fn new(name: impl Into<String>) -> Self {
99 Self {
100 model_name: name.into(),
101 in_order_fields: Vec::new(),
102 css: String::new(),
103 is_cloze: None,
104 card_templates: Vec::new(),
105 }
106 }
107
108 pub fn field(mut self, name: impl Into<String>) -> Self {
110 self.in_order_fields.push(name.into());
111 self
112 }
113
114 pub fn css(mut self, css: impl Into<String>) -> Self {
116 self.css = css.into();
117 self
118 }
119
120 pub fn cloze(mut self, is_cloze: bool) -> Self {
122 self.is_cloze = Some(is_cloze);
123 self
124 }
125
126 pub fn template(
128 mut self,
129 name: impl Into<String>,
130 front: impl Into<String>,
131 back: impl Into<String>,
132 ) -> Self {
133 self.card_templates.push(CreateCardTemplate {
134 name: name.into(),
135 front: front.into(),
136 back: back.into(),
137 });
138 self
139 }
140}
141
142#[derive(Debug, Clone, Serialize)]
144#[serde(rename_all = "camelCase")]
145pub struct FindReplaceParams {
146 #[serde(skip_serializing_if = "Vec::is_empty")]
148 pub notes: Vec<i64>,
149 #[serde(skip_serializing_if = "Option::is_none")]
151 pub action: Option<String>,
152 pub model_name: String,
154 pub field_name: String,
156 pub find_text: String,
158 pub replace_text: String,
160 #[serde(skip_serializing_if = "Option::is_none")]
162 pub regex: Option<bool>,
163 #[serde(skip_serializing_if = "Option::is_none")]
165 pub match_case: Option<bool>,
166}
167
168impl FindReplaceParams {
169 pub fn new(
171 model_name: impl Into<String>,
172 field_name: impl Into<String>,
173 find: impl Into<String>,
174 replace: impl Into<String>,
175 ) -> Self {
176 Self {
177 notes: Vec::new(),
178 action: None,
179 model_name: model_name.into(),
180 field_name: field_name.into(),
181 find_text: find.into(),
182 replace_text: replace.into(),
183 regex: None,
184 match_case: None,
185 }
186 }
187
188 pub fn notes(mut self, notes: Vec<i64>) -> Self {
190 self.notes = notes;
191 self
192 }
193
194 pub fn regex(mut self, enabled: bool) -> Self {
196 self.regex = Some(enabled);
197 self
198 }
199
200 pub fn match_case(mut self, enabled: bool) -> Self {
202 self.match_case = Some(enabled);
203 self
204 }
205}
206
207#[derive(Debug, Clone, Deserialize)]
209pub struct ModelStyling {
210 pub css: String,
212}
213
214pub type FieldsOnTemplates = HashMap<String, Vec<Vec<String>>>;