use serde::Deserialize;
use serde::Serialize;
use std::str;
use strum_macros::EnumString;
#[cfg(feature = "diesel")]
use {
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::types::Varchar,
diesel::{deserialize, not_none, serialize},
diesel::{AsExpression, FromSqlRow},
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumString)]
#[cfg_attr(feature = "diesel", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "diesel", sql_type = "Varchar")]
pub enum NotificationType {
BehaviourRecord,
CanteenOrderStatusChange,
ChildAbsent,
CourseApproved,
CourseProgramApproved,
CourseProgramRejected,
CourseRejected,
CurriculumApproved,
CurriculumRejected,
EmergencyReport,
EventSendLocation,
EventUpdateSessionAccess,
EventVisitSection,
FormRequest,
IncidentReport,
InventoryStuffRequest,
InvoiceRefund,
LessonPlanApproved,
LessonPlanRejected,
MedicBooking,
Payment,
QuizAnswer,
QuizPlayStatusChange,
QuizStarted,
QuizStopped,
SecuritySummon,
TestApproved,
TestGameAccepted,
TestGameInvitation,
TutorLessonApproved,
TutorLessonRejected,
TutorNewExercise,
TutorNewOrder,
TutorOrderApproved,
TutorOrderRejected,
Other,
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for NotificationType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
NotificationType::CourseProgramApproved => out.write_all(b"CourseProgramApproved")?,
NotificationType::CourseApproved => out.write_all(b"CourseApproved")?,
NotificationType::InventoryStuffRequest => out.write_all(b"InventoryStuffRequest")?,
NotificationType::FormRequest => out.write_all(b"FormRequest")?,
NotificationType::QuizPlayStatusChange => out.write_all(b"QuizPlayStatusChange")?,
NotificationType::TutorNewExercise => out.write_all(b"TutorNewExercise")?,
NotificationType::BehaviourRecord => out.write_all(b"BehaviourRecord")?,
NotificationType::LessonPlanApproved => out.write_all(b"LessonPlanApproved")?,
NotificationType::LessonPlanRejected => out.write_all(b"LessonPlanRejected")?,
NotificationType::CurriculumApproved => out.write_all(b"CurriculumApproved")?,
NotificationType::TestApproved => out.write_all(b"TestApproved")?,
NotificationType::ChildAbsent => out.write_all(b"ChildAbsent")?,
NotificationType::CourseRejected => out.write_all(b"CourseRejected")?,
NotificationType::CourseProgramRejected => out.write_all(b"CourseProgramRejected")?,
NotificationType::TutorOrderApproved => out.write_all(b"TutorOrderApproved")?,
NotificationType::TutorNewOrder => out.write_all(b"TutorNewOrder")?,
NotificationType::QuizStarted => out.write_all(b"QuizStarted")?,
NotificationType::QuizStopped => out.write_all(b"QuizStopped")?,
NotificationType::TestGameAccepted => out.write_all(b"TestGameAccepted")?,
NotificationType::CurriculumRejected => out.write_all(b"CurriculumRejected")?,
NotificationType::TutorLessonApproved => out.write_all(b"TutorLessonApproved")?,
NotificationType::TutorLessonRejected => out.write_all(b"TutorLessonRejected")?,
NotificationType::TutorOrderRejected => out.write_all(b"TutorOrderRejected")?,
NotificationType::InvoiceRefund => out.write_all(b"InvoiceRefund")?,
NotificationType::Payment => out.write_all(b"Payment")?,
NotificationType::MedicBooking => out.write_all(b"MedicBooking")?,
NotificationType::EventUpdateSessionAccess => out.write_all(b"EventUpdateSessionAccess")?,
NotificationType::EventVisitSection => out.write_all(b"EventVisitSection")?,
NotificationType::EventSendLocation => out.write_all(b"EventSendLocation")?,
NotificationType::CanteenOrderStatusChange => out.write_all(b"CanteenOrderStatusChange")?,
NotificationType::TestGameInvitation => out.write_all(b"TestGameInvitation")?,
NotificationType::QuizAnswer => out.write_all(b"QuizAnswer")?,
NotificationType::SecuritySummon => out.write_all(b"SecuritySummon")?,
NotificationType::EmergencyReport => out.write_all(b"EmergencyReport")?,
NotificationType::IncidentReport => out.write_all(b"IncidentReport")?,
NotificationType::Other => out.write_all(b"Other")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for NotificationType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"CourseApproved" => Ok(NotificationType::CourseApproved),
b"CourseProgramApproved" => Ok(NotificationType::CourseProgramApproved),
b"InventoryStuffRequest" => Ok(NotificationType::InventoryStuffRequest),
b"FormRequest" => Ok(NotificationType::FormRequest),
b"QuizPlayStatusChange" => Ok(NotificationType::QuizPlayStatusChange),
b"TutorNewExercise" => Ok(NotificationType::TutorNewExercise),
b"BehaviourRecord" => Ok(NotificationType::BehaviourRecord),
b"LessonPlanApproved" => Ok(NotificationType::LessonPlanApproved),
b"LessonPlanRejected" => Ok(NotificationType::LessonPlanRejected),
b"CurriculumApproved" => Ok(NotificationType::CurriculumApproved),
b"TestApproved" => Ok(NotificationType::TestApproved),
b"ChildAbsent" => Ok(NotificationType::ChildAbsent),
b"CourseRejected" => Ok(NotificationType::CourseRejected),
b"CourseProgramRejected" => Ok(NotificationType::CourseProgramRejected),
b"TutorOrderApproved" => Ok(NotificationType::TutorOrderApproved),
b"TutorNewOrder" => Ok(NotificationType::TutorNewOrder),
b"QuizStarted" => Ok(NotificationType::QuizStarted),
b"QuizStopped" => Ok(NotificationType::QuizStopped),
b"TestGameAccepted" => Ok(NotificationType::TestGameAccepted),
b"CurriculumRejected" => Ok(NotificationType::CurriculumRejected),
b"TutorLessonApproved" => Ok(NotificationType::TutorLessonApproved),
b"TutorLessonRejected" => Ok(NotificationType::TutorLessonRejected),
b"TutorOrderRejected" => Ok(NotificationType::TutorOrderRejected),
b"InvoiceRefund" => Ok(NotificationType::InvoiceRefund),
b"Payment" => Ok(NotificationType::Payment),
b"MedicBooking" => Ok(NotificationType::MedicBooking),
b"EventUpdateSessionAccess" => Ok(NotificationType::EventUpdateSessionAccess),
b"EventVisitSection" => Ok(NotificationType::EventVisitSection),
b"EventSendLocation" => Ok(NotificationType::EventSendLocation),
b"CanteenOrderStatusChange" => Ok(NotificationType::CanteenOrderStatusChange),
b"TestGameInvitation" => Ok(NotificationType::TestGameInvitation),
b"QuizAnswer" => Ok(NotificationType::QuizAnswer),
b"SecuritySummon" => Ok(NotificationType::SecuritySummon),
b"EmergencyReport" => Ok(NotificationType::EmergencyReport),
b"IncidentReport" => Ok(NotificationType::IncidentReport),
b"Other" => Ok(NotificationType::Other),
_ => Err("Unrecognized enum variant".into()),
}
}
}