1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use serde::Serialize;
use crate::compound_query::boolean::compound_query_boolean::CompoundQueryBoolean;


#[derive(Debug, Clone, Serialize)]
pub struct Bool {
    #[serde(skip_serializing_if = "Option::is_none")]
    must: Option<Vec<CompoundQueryBoolean>>,
    
    #[serde(skip_serializing_if = "Option::is_none")]
    must_not: Option<Vec<CompoundQueryBoolean>>,
    
    #[serde(skip_serializing_if = "Option::is_none")]
    filter: Option<Vec<CompoundQueryBoolean>>,
    
    #[serde(skip_serializing_if = "Option::is_none")]
    should: Option<Vec<CompoundQueryBoolean>>,
    
    #[serde(skip_serializing_if = "Option::is_none")]
    minimum_should_match: Option<usize>
    
}

impl Bool {
    
    pub fn new() -> Self {
        Self {
            must: None,
            must_not: None,
            should: None,
            filter: None,
            minimum_should_match: None
        }
    }
    
    pub fn must<T,F>(self, must_value: F) -> Self
        where T: Into<CompoundQueryBoolean>,
            F: IntoIterator<Item = T>
    {
        
        Self {
            must: Some(must_value.into_iter().map(|x| x.into()).collect()),
            ..self
        }
    }
    
    pub fn must_not<T,F>(self, must_value: F) -> Self
        where T: Into<CompoundQueryBoolean>,
            F: IntoIterator<Item = T>
    {
        
        Self {
            must_not: Some(must_value.into_iter().map(|x| x.into()).collect()),
            ..self
        }
    }
    
    pub fn should<T,F>(self, must_value: F) -> Self
        where T: Into<CompoundQueryBoolean>,
            F: IntoIterator<Item = T>
    {
        
        Self {
            should: Some(must_value.into_iter().map(|x| x.into()).collect()),
            ..self
        }
    }
    
    pub fn filter<T,F>(self, filter_values: F) -> Self
        where T: Into<CompoundQueryBoolean>,
            F: IntoIterator<Item = T>
    {
        
        Self {
            filter: Some(filter_values.into_iter().map(|x| x.into()).collect()),
            ..self
        }
    }
    
    pub fn minimum_should_match<T: Into<usize>>(self, minimum_should_match : T) -> Self {
        Self {
            minimum_should_match: Some(minimum_should_match.into()),
            ..self
        }
    }
    
}