use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
pub enum Weekday {
Mon = 0,
Tue = 1,
Wed = 2,
Thu = 3,
Fri = 4,
Sat = 5,
Sun = 6,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct PersonalCourseSchedule {
schedule: HashMap<Weekday, Vec<CourseScheduleInformation>>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct CourseScheduleInformation {
name: String,
professor: String,
time: String,
classroom: String,
}
impl CourseScheduleInformation {
pub(crate) fn from_iter<'a>(
iter: &mut impl Iterator<Item = &'a str>,
) -> CourseScheduleInformation {
let mut iter = iter.skip_while(|s| s.is_empty());
CourseScheduleInformation {
name: iter.next().unwrap().to_string(),
professor: iter.next().unwrap().to_string(),
time: iter.next().unwrap().to_string(),
classroom: iter.next().unwrap_or("").to_string(),
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn professor(&self) -> &str {
&self.professor
}
pub fn time(&self) -> &str {
&self.time
}
pub fn classroom(&self) -> &str {
&self.classroom
}
}
impl PersonalCourseSchedule {
pub(super) fn new(schedule: HashMap<Weekday, Vec<CourseScheduleInformation>>) -> Self {
Self { schedule }
}
pub fn schedule(&self) -> &HashMap<Weekday, Vec<CourseScheduleInformation>> {
&self.schedule
}
}