use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Note {
pub id: String,
#[serde(skip)]
pub pk: i64,
pub title: String,
pub text: String,
pub tags: Vec<String>,
pub created: i64,
pub modified: i64,
pub trashed: bool,
pub archived: bool,
pub pinned: bool,
pub locked: bool,
pub encrypted: bool,
pub has_images: bool,
pub has_files: bool,
pub has_source_code: bool,
pub todo_completed: i64,
pub todo_incompleted: i64,
pub attachments: Vec<Attachment>,
pub pinned_in_tags: Vec<String>,
}
impl Note {
pub fn hash(&self) -> String {
use sha2::{Digest, Sha256};
let digest = Sha256::digest(self.text.as_bytes());
format!("{digest:x}")
}
pub fn length(&self) -> i64 {
self.text.len() as i64
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag {
pub name: String,
#[serde(skip)]
pub pk: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attachment {
pub filename: String,
pub size: i64,
pub uuid: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PinRecord {
pub note_id: String,
pub pin: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InsertPosition {
Beginning,
End,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TagPosition {
Top,
#[default]
Bottom,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortField {
Pinned,
Modified,
Created,
Title,
}
impl SortField {
pub fn sql_column(&self) -> &'static str {
match self {
SortField::Pinned => "n.ZPINNED",
SortField::Modified => "n.ZMODIFICATIONDATE",
SortField::Created => "n.ZCREATIONDATE",
SortField::Title => "n.ZTITLE",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortDir {
Asc,
Desc,
}