use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter, DeriveActiveEnum, Serialize, Deserialize,
)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(16))")]
pub enum MatchStrength {
#[sea_orm(string_value = "High")]
High,
#[sea_orm(string_value = "Medium")]
Medium,
#[sea_orm(string_value = "Low")]
Low,
}
impl MatchStrength {
pub fn as_str(&self) -> &'static str {
match self {
Self::High => "High",
Self::Medium => "Medium",
Self::Low => "Low",
}
}
pub fn rank(&self) -> u8 {
match self {
Self::High => 3,
Self::Medium => 2,
Self::Low => 1,
}
}
pub fn at_least(&self, minimum: MatchStrength) -> bool {
self.rank() >= minimum.rank()
}
pub fn parse(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"high" => Some(Self::High),
"medium" | "med" => Some(Self::Medium),
"low" => Some(Self::Low),
_ => None,
}
}
}
impl fmt::Display for MatchStrength {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "semantic_matched")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(indexed)]
pub extract_id: i32,
#[sea_orm(indexed)]
pub historical_id: i32,
#[sea_orm(indexed)]
pub strength: MatchStrength,
#[sea_orm(column_type = "Text")]
pub evidence: String,
#[sea_orm(belongs_to, from = "extract_id", to = "id")]
pub extract: Option<super::project_semantic::Entity>,
#[sea_orm(belongs_to, from = "historical_id", to = "id")]
pub historical: Option<super::historical_semantic::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}