use std::path::PathBuf;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Card {
pub inner: CardInner,
pub path: PathBuf,
pub score: usize,
pub due_date: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Hash, Eq, Serialize, Deserialize, PartialEq, PartialOrd, Ord)]
pub struct CardInner {
pub question: String,
pub answer: String,
#[serde(default)]
pub question_type: CardType,
}
impl From<CardInner> for Card {
fn from(val: CardInner) -> Self {
Card {
inner: CardInner {
question: val.question,
answer: val.answer,
question_type: val.question_type,
},
path: Default::default(),
score: Default::default(),
due_date: Default::default(),
}
}
}
impl From<Card> for CardInner {
fn from(card: Card) -> Self {
CardInner {
question: card.inner.question,
answer: card.inner.answer,
question_type: card.inner.question_type,
}
}
}
impl AsRef<CardInner> for CardInner {
fn as_ref(&self) -> &CardInner {
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, PartialOrd, Ord)]
pub enum CardType {
Memory,
Input,
}
impl Default for CardType {
fn default() -> Self {
Self::Memory
}
}