use serde::{Deserialize, Serialize};
use crate::http::{Http, HttpError};
use crate::http::routing::Route;
use crate::model::channel::{Channel, ChannelId};
#[derive(Debug, Default, Serialize)]
pub struct EditChannel {
#[serde(skip_serializing_if = "Option::is_none")]
pub archived: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub nsfw: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub remove: Vec<FieldsChannel>
}
#[derive(Debug, Serialize, Deserialize)]
pub enum FieldsChannel {
Description,
Icon,
DefaultPermissions,
Voice,
}
impl EditChannel {
pub fn new() -> Self {
Self::default()
}
pub fn archived(mut self, archived: bool) -> Self {
self.archived = Some(archived);
self
}
pub fn description(mut self, description: String) -> Self {
self.description = Some(description);
self
}
pub fn icon(mut self, icon: String) -> Self {
self.icon = Some(icon);
self
}
pub fn name(mut self, name: String) -> Self {
self.name = Some(name);
self
}
pub fn nsfw(mut self, nsfw: bool) -> Self {
self.nsfw = Some(nsfw);
self
}
pub fn owner(mut self, owner: String) -> Self {
self.owner = Some(owner);
self
}
pub fn remove(mut self, remove: Vec<FieldsChannel>) -> Self {
self.remove = remove;
self
}
pub(crate) async fn execute(self, http: &Http, channel_id: &ChannelId) -> Result<Channel, HttpError> {
let route = Route::EditChannel { channel_id: &channel_id.0 };
let response = http.execute::<Self, Channel>(route, self).await?;
Ok(response)
}
}