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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use super::location::Local;

#[derive(Debug, Default)]
pub struct ClanSearchOptionsBuilder {
    options: ClanSearchOptions,
}

#[derive(Debug, Default)]
pub struct ClanSearchOptions {
    name: Option<String>,
    war_frequency: Option<String>,
    location_id: Option<i32>,
    min_members: Option<i32>,
    max_members: Option<i32>,
    min_clan_points: Option<i32>,
    min_clan_level: Option<i8>,
    limit: Option<i32>,
    after: Option<String>,
    before: Option<String>,
    label_ids: Option<Vec<String>>,

    pub(crate) items: Vec<(String, String)>,
}

// implement iter for ClanSearchOptions by iterating over every field

impl ClanSearchOptionsBuilder {
    #[must_use]
    pub fn new() -> Self {
        let mut s = Self { options: ClanSearchOptions::default() };
        // empty vec of (String, String) with size of 11
        s.options.items = vec![(String::new(), String::new()); 11];
        s
    }

    #[must_use]
    pub fn name(mut self, name: String) -> Self {
        self.options.name = Some(name.clone());
        self.options.items[0] = ("name".to_string(), name);
        self
    }

    #[must_use]
    pub fn war_frequency(mut self, war_frequency: String) -> Self {
        self.options.war_frequency = Some(war_frequency.clone());
        self.options.items[1] = ("warFrequency".to_string(), war_frequency);
        self
    }

    #[must_use]
    pub fn location_id(mut self, location_id: Local) -> Self {
        let i = location_id as i32;
        self.options.location_id = Some(i);
        self.options.items[2] = ("locationId".to_string(), (i).to_string());
        self
    }

    #[must_use]
    pub fn min_members(mut self, min_members: i32) -> Self {
        if min_members >= 2 {
            self.options.min_members = Some(min_members);
            self.options.items[3] = ("minMembers".to_string(), min_members.to_string());
        }
        self
    }

    #[must_use]
    pub fn max_members(mut self, max_members: i32) -> Self {
        if max_members <= 50 {
            self.options.max_members = Some(max_members);
            self.options.items[4] = ("maxMembers".to_string(), max_members.to_string());
        }
        self
    }

    #[must_use]
    pub fn min_clan_points(mut self, min_clan_points: i32) -> Self {
        self.options.min_clan_points = Some(min_clan_points);
        self.options.items[5] = ("minClanPoints".to_string(), min_clan_points.to_string());
        self
    }

    #[must_use]
    pub fn min_clan_level(mut self, min_clan_level: i8) -> Self {
        if min_clan_level >= 2 {
            self.options.min_clan_level = Some(min_clan_level);
            self.options.items[6] = ("minClanLevel".to_string(), min_clan_level.to_string());
        }
        self
    }

    #[must_use]
    pub fn limit(mut self, limit: i32) -> Self {
        self.options.limit = Some(limit);
        self.options.items[7] = ("limit".to_string(), limit.to_string());
        self
    }

    #[must_use]
    pub fn after(mut self, after: String) -> Self {
        self.options.after = Some(after.clone());
        self.options.items[8] = ("after".to_string(), after);
        self
    }

    #[must_use]
    pub fn before(mut self, before: String) -> Self {
        self.options.before = Some(before.clone());
        self.options.items[9] = ("before".to_string(), before);
        self
    }

    #[must_use]
    pub fn label_ids(mut self, label_ids: &[String]) -> Self {
        self.options.label_ids = Some(label_ids.to_vec());
        self.options.items[10] = ("labelIds".to_string(), label_ids.join(","));
        self
    }

    #[must_use]
    pub fn build(self) -> ClanSearchOptions {
        self.options
    }
}