use std::fmt;
use std::fmt::Formatter;
use std::str;
use std::str::FromStr;
use serde::Deserialize;
use serde::Serialize;
#[cfg(feature = "diesel")]
use {
diesel::{deserialize, not_none, serialize},
diesel::{AsExpression, FromSqlRow},
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::types::Varchar,
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
feature = "diesel",
derive(AsExpression, FromSqlRow),
sql_type = "Varchar"
)]
pub enum BehavioutType {
Criminal,
Aggressive,
Physical,
WeaponUse,
WeaponPosession,
WeaponImplementation,
DrugUse,
DrugPosession,
DrugSupply,
CriminalBehaviour,
ConcerningBehaviour,
PersistentRiskOthers,
PropertyDestruction,
CyberBullying,
Bullying,
PsychologicalAbuse,
VerbalAbuse,
Racism,
Discrimination,
MisuseTechnology,
Assault,
Positive,
Neutral,
None,
}
impl BehavioutType {
pub fn to_text(&self)->String {
match self {
BehavioutType::Criminal => "Criminal behaviour".to_string(),
BehavioutType::Positive => "Positive".to_string(),
BehavioutType::Neutral => "Neutral".to_string(),
BehavioutType::Aggressive => "Aggressive behaviour".to_string(),
BehavioutType::Physical => "Physical violence".to_string(),
BehavioutType::WeaponUse => "Use of a prohibited weapon, firearm or knife".to_string(),
BehavioutType::WeaponPosession => "Possession of a prohibited weapon, firearm or knife".to_string(),
BehavioutType::WeaponImplementation => "Use of implement as a weapon".to_string(),
BehavioutType::DrugUse => "Use of a suspected drug or illegal substance".to_string(),
BehavioutType::DrugPosession => "Possession of a suspected drug or illegal substance ".to_string(),
BehavioutType::DrugSupply => "Supply of suspected drug or illegal substance".to_string(),
BehavioutType::CriminalBehaviour => "Serious criminal behaviour related to the school".to_string(),
BehavioutType::ConcerningBehaviour => "Serious behaviours of concern - pending expulsion decision".to_string(),
BehavioutType::PersistentRiskOthers => "Continuing persistent behaviour posing unacceptable risk to anotherperson's learning and/or wellbeing".to_string(),
BehavioutType::PropertyDestruction => "Destruction of property that poses unacceptable risk to health and safety ".to_string(),
BehavioutType::CyberBullying => "Cyber-bullying".to_string(),
BehavioutType::Bullying => "Bullying".to_string(),
BehavioutType::PsychologicalAbuse => "Psychological abuse".to_string(),
BehavioutType::VerbalAbuse =>"Verbal abuse".to_string(),
BehavioutType::Racism => "Racism".to_string(),
BehavioutType::Discrimination => "Discrimination".to_string(),
BehavioutType::MisuseTechnology => "Misuse of technology".to_string(),
BehavioutType::Assault => "Assault".to_string(),
BehavioutType::None => "None".to_string(),
}
}
}
impl fmt::Display for BehavioutType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl Default for BehavioutType {
fn default() -> Self {
BehavioutType::None
}
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for BehavioutType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
BehavioutType::Criminal => out.write_all(b"Criminal")?,
BehavioutType::Neutral => out.write_all(b"Neutral")?,
BehavioutType::Positive => out.write_all(b"Positive")?,
BehavioutType::Aggressive => out.write_all(b"Aggressive")?,
BehavioutType::Physical => out.write_all(b"Physical")?,
BehavioutType::WeaponUse => out.write_all(b"WeaponUse")?,
BehavioutType::WeaponPosession => out.write_all(b"WeaponPosession")?,
BehavioutType::WeaponImplementation => out.write_all(b"WeaponImplementation")?,
BehavioutType::DrugUse => out.write_all(b"DrugUse")?,
BehavioutType::DrugPosession => out.write_all(b"DrugPosession")?,
BehavioutType::DrugSupply => out.write_all(b"DrugSupply")?,
BehavioutType::CriminalBehaviour => out.write_all(b"CriminalBehaviour")?,
BehavioutType::ConcerningBehaviour => out.write_all(b"ConcerningBehaviour")?,
BehavioutType::PersistentRiskOthers => out.write_all(b"PersistentRiskOthers")?,
BehavioutType::PropertyDestruction => out.write_all(b"PropertyDestruction")?,
BehavioutType::CyberBullying => out.write_all(b"CyberBullying")?,
BehavioutType::Bullying => out.write_all(b"Bullying")?,
BehavioutType::PsychologicalAbuse => out.write_all(b"PsychologicalAbuse")?,
BehavioutType::VerbalAbuse => out.write_all(b"VerbalAbuse")?,
BehavioutType::Racism => out.write_all(b"Racism")?,
BehavioutType::Discrimination => out.write_all(b"Discrimination")?,
BehavioutType::MisuseTechnology => out.write_all(b"MisuseTechnology")?,
BehavioutType::Assault => out.write_all(b"Assault")?,
BehavioutType::None => out.write_all(b"None")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for BehavioutType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Criminal" => Ok(BehavioutType::Criminal),
b"Positive" => Ok(BehavioutType::Positive),
b"Neutral" => Ok(BehavioutType::Neutral),
b"Aggressive" => Ok(BehavioutType::Aggressive),
b"Physical" => Ok(BehavioutType::Physical),
b"WeaponUse" => Ok(BehavioutType::WeaponUse),
b"WeaponPosession" => Ok(BehavioutType::WeaponPosession),
b"WeaponImplementation" => Ok(BehavioutType::WeaponImplementation),
b"DrugUse" => Ok(BehavioutType::DrugUse),
b"DrugPosession" => Ok(BehavioutType::DrugPosession),
b"DrugSupply" => Ok(BehavioutType::DrugSupply),
b"CriminalBehaviour" => Ok(BehavioutType::CriminalBehaviour),
b"ConcerningBehaviour" => Ok(BehavioutType::ConcerningBehaviour),
b"PersistentRiskOthers" => Ok(BehavioutType::PersistentRiskOthers),
b"PropertyDestruction" => Ok(BehavioutType::PropertyDestruction),
b"CyberBullying" => Ok(BehavioutType::CyberBullying),
b"Bullying" => Ok(BehavioutType::Bullying),
b"PsychologicalAbuse" => Ok(BehavioutType::PsychologicalAbuse),
b"VerbalAbuse" => Ok(BehavioutType::VerbalAbuse),
b"Racism" => Ok(BehavioutType::Racism),
b"Discrimination" => Ok(BehavioutType::Discrimination),
b"MisuseTechnology" => Ok(BehavioutType::MisuseTechnology),
b"Assault" => Ok(BehavioutType::Assault),
b"None" => Ok(BehavioutType::None),
_ => Err("Unrecognized enum variant".into()),
}
}
}