Skip to main content

stoat/builders/
edit_role.rs

1use stoat_models::v0::{DataEditRole, FieldsRole, Role};
2
3use crate::{HttpClient, error::Error};
4
5pub struct EditRoleBuilder {
6    http: HttpClient,
7    server_id: String,
8    role_id: String,
9    data: DataEditRole,
10}
11
12impl EditRoleBuilder {
13    pub fn new(http: HttpClient, server_id: String, role_id: String) -> Self {
14        Self {
15            http,
16            server_id,
17            role_id,
18            data: DataEditRole {
19                name: None,
20                colour: None,
21                hoist: None,
22                rank: None,
23                remove: Vec::new(),
24            },
25        }
26    }
27
28    pub fn name(&mut self, name: String) -> &mut Self {
29        self.data.name = Some(name);
30
31        self
32    }
33
34    pub fn colour(&mut self, colour: Option<String>) -> &mut Self {
35        if colour.is_some() {
36            self.data.colour = colour;
37        } else {
38            self.data.remove.push(FieldsRole::Colour);
39        };
40
41        self
42    }
43
44    pub fn hoist(&mut self, hoist: bool) -> &mut Self {
45        self.data.hoist = Some(hoist);
46
47        self
48    }
49
50    pub async fn build(&self) -> Result<Role, Error> {
51        self.http
52            .edit_role(&self.server_id, &self.role_id, &self.data)
53            .await
54    }
55}