use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModelInfo {
pub name: String,
#[serde(rename = "id")]
pub model_id: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModelField {
pub name: String,
#[serde(default)]
pub ord: i32,
#[serde(default)]
pub sticky: bool,
#[serde(default)]
pub rtl: bool,
#[serde(default)]
pub font: String,
#[serde(default)]
pub size: i32,
#[serde(default)]
pub description: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CardTemplate {
#[serde(rename = "Front")]
pub front: String,
#[serde(rename = "Back")]
pub back: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateCardTemplate {
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "Front")]
pub front: String,
#[serde(rename = "Back")]
pub back: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct FieldFont {
pub font: String,
pub size: i32,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateModelParams {
pub model_name: String,
pub in_order_fields: Vec<String>,
pub css: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_cloze: Option<bool>,
pub card_templates: Vec<CreateCardTemplate>,
}
impl CreateModelParams {
pub fn new(name: impl Into<String>) -> Self {
Self {
model_name: name.into(),
in_order_fields: Vec::new(),
css: String::new(),
is_cloze: None,
card_templates: Vec::new(),
}
}
pub fn field(mut self, name: impl Into<String>) -> Self {
self.in_order_fields.push(name.into());
self
}
pub fn css(mut self, css: impl Into<String>) -> Self {
self.css = css.into();
self
}
pub fn cloze(mut self, is_cloze: bool) -> Self {
self.is_cloze = Some(is_cloze);
self
}
pub fn template(
mut self,
name: impl Into<String>,
front: impl Into<String>,
back: impl Into<String>,
) -> Self {
self.card_templates.push(CreateCardTemplate {
name: name.into(),
front: front.into(),
back: back.into(),
});
self
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FindReplaceParams {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub notes: Vec<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<String>,
pub model_name: String,
pub field_name: String,
pub find_text: String,
pub replace_text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub regex: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub match_case: Option<bool>,
}
impl FindReplaceParams {
pub fn new(
model_name: impl Into<String>,
field_name: impl Into<String>,
find: impl Into<String>,
replace: impl Into<String>,
) -> Self {
Self {
notes: Vec::new(),
action: None,
model_name: model_name.into(),
field_name: field_name.into(),
find_text: find.into(),
replace_text: replace.into(),
regex: None,
match_case: None,
}
}
pub fn notes(mut self, notes: Vec<i64>) -> Self {
self.notes = notes;
self
}
pub fn regex(mut self, enabled: bool) -> Self {
self.regex = Some(enabled);
self
}
pub fn match_case(mut self, enabled: bool) -> Self {
self.match_case = Some(enabled);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ModelStyling {
pub css: String,
}
pub type FieldsOnTemplates = HashMap<String, Vec<Vec<String>>>;