1use crate::models::{Card, Rating, RecordLog, SchedulingInfo};
2use crate::parameters::Parameters;
3use crate::scheduler_basic::BasicScheduler;
4use crate::scheduler_longterm::LongtermScheduler;
5use crate::ImplScheduler;
6
7use chrono::{DateTime, Utc};
8
9#[derive(Debug, Default, Clone)]
10pub struct FSRS {
11 parameters: Parameters,
12}
13
14impl FSRS {
15 pub const fn new(parameters: Parameters) -> Self {
16 Self { parameters }
17 }
18
19 pub fn scheduler(&self, card: Card, now: DateTime<Utc>) -> Box<dyn ImplScheduler> {
20 if self.parameters.enable_short_term {
21 Box::new(BasicScheduler::new(self.parameters.clone(), card, now))
22 } else {
23 Box::new(LongtermScheduler::new(self.parameters.clone(), card, now))
24 }
25 }
26
27 pub fn repeat(&self, card: Card, now: DateTime<Utc>) -> RecordLog {
28 self.scheduler(card, now).preview()
29 }
30
31 pub fn next(&self, card: Card, now: DateTime<Utc>, rating: Rating) -> SchedulingInfo {
32 self.scheduler(card, now).review(rating)
33 }
34}