Skip to main content

backbone_banking/domain/entity/
match_method.rs

1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "match_method", rename_all = "snake_case")]
11pub enum MatchMethod {
12    Manual,
13    Exact,
14    Fuzzy,
15    AutoRule,
16}
17
18impl std::fmt::Display for MatchMethod {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Manual => write!(f, "manual"),
22            Self::Exact => write!(f, "exact"),
23            Self::Fuzzy => write!(f, "fuzzy"),
24            Self::AutoRule => write!(f, "auto_rule"),
25        }
26    }
27}
28
29impl FromStr for MatchMethod {
30    type Err = String;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_lowercase().as_str() {
34            "manual" => Ok(Self::Manual),
35            "exact" => Ok(Self::Exact),
36            "fuzzy" => Ok(Self::Fuzzy),
37            "auto_rule" => Ok(Self::AutoRule),
38            _ => Err(format!("Unknown MatchMethod variant: {}", s)),
39        }
40    }
41}
42
43impl Default for MatchMethod {
44    fn default() -> Self {
45        Self::Manual
46    }
47}