1
use crate::types::{AccountSuggestion, TagSuggestion};
2

            
3
pub trait Suggestion: Clone + serde::de::DeserializeOwned + 'static {
4
    fn display_text(&self) -> &str;
5
    fn matches(&self, query: &str) -> bool;
6
    fn get_id(&self) -> &str;
7
}
8

            
9
impl Suggestion for AccountSuggestion {
10
    fn display_text(&self) -> &str {
11
        &self.name
12
    }
13

            
14
4
    fn matches(&self, query: &str) -> bool {
15
4
        self.name.to_lowercase().contains(&query.to_lowercase())
16
4
    }
17

            
18
1
    fn get_id(&self) -> &str {
19
1
        &self.id
20
1
    }
21
}
22

            
23
impl Suggestion for TagSuggestion {
24
    fn display_text(&self) -> &str {
25
        &self.name
26
    }
27

            
28
6
    fn matches(&self, query: &str) -> bool {
29
6
        let q = query.to_lowercase();
30
6
        self.name.to_lowercase().contains(&q)
31
3
            || self
32
3
                .value
33
3
                .as_ref()
34
2
                .is_some_and(|v| v.to_lowercase().contains(&q))
35
6
    }
36

            
37
1
    fn get_id(&self) -> &str {
38
1
        &self.name
39
1
    }
40
}
41

            
42
#[cfg(test)]
43
#[path = "suggestion_tests.rs"]
44
mod tests;