use std::fmt;
use std::sync::Arc;
use futures::future::BoxFuture;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LessonScope {
pub agent: String,
pub user: Option<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct LessonNotes {
pub text: String,
pub ids: Vec<String>,
}
impl LessonNotes {
pub fn is_empty(&self) -> bool {
self.text.is_empty()
}
}
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[error("{message}")]
pub struct LearningError {
pub kind: &'static str,
pub message: String,
}
impl LearningError {
pub fn new(kind: &'static str, message: impl Into<String>) -> Self {
Self { kind, message: message.into() }
}
}
pub trait LessonSource: Send + Sync + fmt::Debug {
fn notes<'a>(&'a self, scope: &'a LessonScope) -> BoxFuture<'a, Result<LessonNotes, LearningError>>;
}
#[derive(Clone, Debug)]
pub struct Lessons(pub Arc<dyn LessonSource>);
impl Lessons {
pub fn new(source: Arc<dyn LessonSource>) -> Self {
Self(source)
}
}